blob: 689ed1e9d16de984494ee3f707d598ba9997644d [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 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
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010057 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
58 int64_t now_us);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010059
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010060 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010061 // Sends RTCP packets.
62 void SendPacket();
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010063 // Generate Report Blocks to be send in Sender or Receiver Report.
64 std::vector<rtcp::ReportBlock> CreateReportBlocks();
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010065
Danil Chapovalov398a7c62017-10-24 17:07:05 +020066 const RtcpTransceiverConfig config_;
67
Danil Chapovalovd3282292017-11-13 13:46:02 +010068 rtc::Optional<rtcp::Remb> remb_;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010069 std::map<uint32_t, SenderReportTimes> last_received_sender_reports_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010070 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
71
Danil Chapovalov398a7c62017-10-24 17:07:05 +020072 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
73};
74
75} // namespace webrtc
76
77#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_