blob: aed850b07af282c2cdaac6a264c6e8e80fb485ab [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 Chapovalovd3282292017-11-13 13:46:02 +010022#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010023#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020024#include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
25#include "rtc_base/constructormagic.h"
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010026#include "rtc_base/weak_ptr.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010027#include "system_wrappers/include/ntp_time.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020028
29namespace webrtc {
30//
31// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
32//
33// This class is not thread-safe.
34class RtcpTransceiverImpl {
35 public:
36 explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
37 ~RtcpTransceiverImpl();
38
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010039 // Handles incoming rtcp packets.
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010040 void ReceivePacket(rtc::ArrayView<const uint8_t> packet, int64_t now_us);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010041
Danil Chapovalov398a7c62017-10-24 17:07:05 +020042 // Sends RTCP packets starting with a sender or receiver report.
43 void SendCompoundPacket();
44
Danil Chapovalovd3282292017-11-13 13:46:02 +010045 // (REMB) Receiver Estimated Max Bitrate.
46 // Includes REMB in following compound packets.
47 void SetRemb(int bitrate_bps, std::vector<uint32_t> ssrcs);
48 // Stops sending REMB in following compound packets.
49 void UnsetRemb();
50
Danil Chapovalova7e418c2017-11-21 11:08:53 +010051 void RequestKeyFrame(rtc::ArrayView<const uint32_t> ssrcs);
52
Danil Chapovalov398a7c62017-10-24 17:07:05 +020053 private:
Danil Chapovalova7e418c2017-11-21 11:08:53 +010054 class PacketSender;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010055 struct SenderReportTimes {
56 int64_t local_received_time_us;
57 NtpTime remote_sent_time;
58 };
59
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010060 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
61 int64_t now_us);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010062
Danil Chapovalova7e418c2017-11-21 11:08:53 +010063 void ReschedulePeriodicCompoundPackets();
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010064 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010065 // Creates compound RTCP packet, as defined in
66 // https://tools.ietf.org/html/rfc5506#section-2
67 void CreateCompoundPacket(PacketSender* sender);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010068 // Sends RTCP packets.
Danil Chapovalova7e418c2017-11-21 11:08:53 +010069 void SendPeriodicCompoundPacket();
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010070 // Generate Report Blocks to be send in Sender or Receiver Report.
71 std::vector<rtcp::ReportBlock> CreateReportBlocks();
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010072
Danil Chapovalov398a7c62017-10-24 17:07:05 +020073 const RtcpTransceiverConfig config_;
74
Danil Chapovalovd3282292017-11-13 13:46:02 +010075 rtc::Optional<rtcp::Remb> remb_;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010076 std::map<uint32_t, SenderReportTimes> last_received_sender_reports_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010077 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
78
Danil Chapovalov398a7c62017-10-24 17:07:05 +020079 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
80};
81
82} // namespace webrtc
83
84#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_