Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 1 | /* |
| 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 Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 14 | #include <map> |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 15 | #include <memory> |
| 16 | #include <string> |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 17 | #include <vector> |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 18 | |
| 19 | #include "api/array_view.h" |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 21 | #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 22 | #include "modules/rtp_rtcp/source/rtcp_transceiver_config.h" |
| 23 | #include "rtc_base/constructormagic.h" |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 24 | #include "rtc_base/weak_ptr.h" |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 25 | #include "system_wrappers/include/ntp_time.h" |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | // |
| 29 | // Manage incoming and outgoing rtcp messages for multiple BUNDLED streams. |
| 30 | // |
| 31 | // This class is not thread-safe. |
| 32 | class RtcpTransceiverImpl { |
| 33 | public: |
| 34 | explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config); |
| 35 | ~RtcpTransceiverImpl(); |
| 36 | |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 37 | // Handles incoming rtcp packets. |
| 38 | void ReceivePacket(rtc::ArrayView<const uint8_t> packet); |
| 39 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 40 | // Sends RTCP packets starting with a sender or receiver report. |
| 41 | void SendCompoundPacket(); |
| 42 | |
| 43 | private: |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 44 | 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 Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 51 | void ReschedulePeriodicCompoundPackets(int64_t delay_ms); |
| 52 | // Sends RTCP packets. |
| 53 | void SendPacket(); |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 54 | // Generate Report Blocks to be send in Sender or Receiver Report. |
| 55 | std::vector<rtcp::ReportBlock> CreateReportBlocks(); |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 56 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 57 | const RtcpTransceiverConfig config_; |
| 58 | |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 59 | std::map<uint32_t, SenderReportTimes> last_received_sender_reports_; |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 60 | rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_; |
| 61 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 62 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl); |
| 63 | }; |
| 64 | |
| 65 | } // namespace webrtc |
| 66 | |
| 67 | #endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_ |