blob: 83e6087780238696b35d6b060667df08182faa54 [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 Chapovalov7ca9ae22017-12-13 12:26:17 +010041 void AddMediaReceiverObserver(uint32_t remote_ssrc,
42 MediaReceiverRtcpObserver* observer);
43 void RemoveMediaReceiverObserver(uint32_t remote_ssrc,
44 MediaReceiverRtcpObserver* observer);
45
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();
52
Danil Chapovalov327c43c2017-11-27 17:23:04 +010053 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
54
Danil Chapovalov8d19e032017-11-28 19:53:33 +010055 void SendPictureLossIndication(uint32_t ssrc);
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010056 void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010057
Danil Chapovalov398a7c62017-10-24 17:07:05 +020058 private:
Danil Chapovalova7e418c2017-11-21 11:08:53 +010059 class PacketSender;
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010060 struct RemoteSenderState;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010061
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010062 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
63 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010064 // Individual rtcp packet handlers.
65 void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
Danil Chapovalov319a6752017-11-30 14:56:52 +010066 void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
67 int64_t now_us);
68 void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
69 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010070 // Extended Reports blocks handlers.
71 void HandleDlrr(const rtcp::Dlrr& dlrr, int64_t now_us);
72 void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
73 uint32_t remote_ssrc);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010074
Danil Chapovalova7e418c2017-11-21 11:08:53 +010075 void ReschedulePeriodicCompoundPackets();
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010076 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010077 // Creates compound RTCP packet, as defined in
78 // https://tools.ietf.org/html/rfc5506#section-2
79 void CreateCompoundPacket(PacketSender* sender);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010080 // Sends RTCP packets.
Danil Chapovalova7e418c2017-11-21 11:08:53 +010081 void SendPeriodicCompoundPacket();
Danil Chapovalov8d19e032017-11-28 19:53:33 +010082 void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010083 // Generate Report Blocks to be send in Sender or Receiver Report.
Danil Chapovalov319a6752017-11-30 14:56:52 +010084 std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010085
Danil Chapovalov398a7c62017-10-24 17:07:05 +020086 const RtcpTransceiverConfig config_;
87
Danil Chapovalovd3282292017-11-13 13:46:02 +010088 rtc::Optional<rtcp::Remb> remb_;
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010089 // TODO(danilchap): Remove entries from remote_senders_ that are no longer
90 // needed.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010091 std::map<uint32_t, RemoteSenderState> remote_senders_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010092 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
93
Danil Chapovalov398a7c62017-10-24 17:07:05 +020094 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
95};
96
97} // namespace webrtc
98
99#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_