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 | d328229 | 2017-11-13 13:46:02 +0100 | [diff] [blame] | 20 | #include "api/optional.h" |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 21 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
Danil Chapovalov | d328229 | 2017-11-13 13:46:02 +0100 | [diff] [blame] | 22 | #include "modules/rtp_rtcp/source/rtcp_packet/remb.h" |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h" |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 24 | #include "modules/rtp_rtcp/source/rtcp_transceiver_config.h" |
| 25 | #include "rtc_base/constructormagic.h" |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 26 | #include "rtc_base/weak_ptr.h" |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 27 | #include "system_wrappers/include/ntp_time.h" |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | // |
| 31 | // Manage incoming and outgoing rtcp messages for multiple BUNDLED streams. |
| 32 | // |
| 33 | // This class is not thread-safe. |
| 34 | class RtcpTransceiverImpl { |
| 35 | public: |
| 36 | explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config); |
| 37 | ~RtcpTransceiverImpl(); |
| 38 | |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 39 | void ReceivePacket(rtc::ArrayView<const uint8_t> packet, int64_t now_us); |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 40 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 41 | void SendCompoundPacket(); |
| 42 | |
Danil Chapovalov | d328229 | 2017-11-13 13:46:02 +0100 | [diff] [blame] | 43 | void SetRemb(int bitrate_bps, std::vector<uint32_t> ssrcs); |
Danil Chapovalov | d328229 | 2017-11-13 13:46:02 +0100 | [diff] [blame] | 44 | void UnsetRemb(); |
| 45 | |
Danil Chapovalov | 327c43c | 2017-11-27 17:23:04 +0100 | [diff] [blame] | 46 | void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers); |
| 47 | |
Danil Chapovalov | 8d19e03 | 2017-11-28 19:53:33 +0100 | [diff] [blame] | 48 | void SendPictureLossIndication(uint32_t ssrc); |
Danil Chapovalov | 2ddf98d | 2017-11-22 14:00:41 +0100 | [diff] [blame] | 49 | void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs); |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 50 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 51 | private: |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 52 | class PacketSender; |
Danil Chapovalov | 2ddf98d | 2017-11-22 14:00:41 +0100 | [diff] [blame] | 53 | struct RemoteSenderState; |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 54 | |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 55 | void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header, |
| 56 | int64_t now_us); |
Danil Chapovalov | 319a675 | 2017-11-30 14:56:52 +0100 | [diff] [blame^] | 57 | void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header, |
| 58 | int64_t now_us); |
| 59 | void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header, |
| 60 | int64_t now_us); |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 61 | |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 62 | void ReschedulePeriodicCompoundPackets(); |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 63 | void SchedulePeriodicCompoundPackets(int64_t delay_ms); |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 64 | // Creates compound RTCP packet, as defined in |
| 65 | // https://tools.ietf.org/html/rfc5506#section-2 |
| 66 | void CreateCompoundPacket(PacketSender* sender); |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 67 | // Sends RTCP packets. |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 68 | void SendPeriodicCompoundPacket(); |
Danil Chapovalov | 8d19e03 | 2017-11-28 19:53:33 +0100 | [diff] [blame] | 69 | void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet); |
Danil Chapovalov | d2f37d8 | 2017-11-09 15:42:28 +0100 | [diff] [blame] | 70 | // Generate Report Blocks to be send in Sender or Receiver Report. |
Danil Chapovalov | 319a675 | 2017-11-30 14:56:52 +0100 | [diff] [blame^] | 71 | std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us); |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 72 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 73 | const RtcpTransceiverConfig config_; |
| 74 | |
Danil Chapovalov | d328229 | 2017-11-13 13:46:02 +0100 | [diff] [blame] | 75 | rtc::Optional<rtcp::Remb> remb_; |
Danil Chapovalov | 2ddf98d | 2017-11-22 14:00:41 +0100 | [diff] [blame] | 76 | std::map<uint32_t, RemoteSenderState> remote_senders_; |
Danil Chapovalov | 8c8d49e | 2017-10-30 15:21:41 +0100 | [diff] [blame] | 77 | rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_; |
| 78 | |
Danil Chapovalov | 398a7c6 | 2017-10-24 17:07:05 +0200 | [diff] [blame] | 79 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl); |
| 80 | }; |
| 81 | |
| 82 | } // namespace webrtc |
| 83 | |
| 84 | #endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_ |