blob: db702ec2d254649f135b9f43317061aaca52eb23 [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 Chapovalovd2f37d82017-11-09 15:42:28 +010020#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
21#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020022#include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
23#include "rtc_base/constructormagic.h"
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010024#include "rtc_base/weak_ptr.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010025#include "system_wrappers/include/ntp_time.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020026
27namespace webrtc {
28//
29// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
30//
31// This class is not thread-safe.
32class RtcpTransceiverImpl {
33 public:
34 explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
35 ~RtcpTransceiverImpl();
36
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010037 // Handles incoming rtcp packets.
38 void ReceivePacket(rtc::ArrayView<const uint8_t> packet);
39
Danil Chapovalov398a7c62017-10-24 17:07:05 +020040 // Sends RTCP packets starting with a sender or receiver report.
41 void SendCompoundPacket();
42
43 private:
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010044 struct SenderReportTimes {
45 int64_t local_received_time_us;
46 NtpTime remote_sent_time;
47 };
48
49 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header);
50
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010051 void ReschedulePeriodicCompoundPackets(int64_t delay_ms);
52 // Sends RTCP packets.
53 void SendPacket();
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010054 // Generate Report Blocks to be send in Sender or Receiver Report.
55 std::vector<rtcp::ReportBlock> CreateReportBlocks();
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010056
Danil Chapovalov398a7c62017-10-24 17:07:05 +020057 const RtcpTransceiverConfig config_;
58
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010059 std::map<uint32_t, SenderReportTimes> last_received_sender_reports_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010060 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
61
Danil Chapovalov398a7c62017-10-24 17:07:05 +020062 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
63};
64
65} // namespace webrtc
66
67#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_