blob: 81f0cace9ce74cc417811c1c308ef1663e6772c2 [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.
40 void ReceivePacket(rtc::ArrayView<const uint8_t> packet);
41
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 Chapovalov398a7c62017-10-24 17:07:05 +020051 private:
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010052 struct SenderReportTimes {
53 int64_t local_received_time_us;
54 NtpTime remote_sent_time;
55 };
56
57 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header);
58
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010059 void ReschedulePeriodicCompoundPackets(int64_t delay_ms);
60 // Sends RTCP packets.
61 void SendPacket();
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010062 // Generate Report Blocks to be send in Sender or Receiver Report.
63 std::vector<rtcp::ReportBlock> CreateReportBlocks();
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010064
Danil Chapovalov398a7c62017-10-24 17:07:05 +020065 const RtcpTransceiverConfig config_;
66
Danil Chapovalovd3282292017-11-13 13:46:02 +010067 rtc::Optional<rtcp::Remb> remb_;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010068 std::map<uint32_t, SenderReportTimes> last_received_sender_reports_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010069 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
70
Danil Chapovalov398a7c62017-10-24 17:07:05 +020071 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
72};
73
74} // namespace webrtc
75
76#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_