• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONFIG_H_
12 #define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_CONFIG_H_
13 
14 #include <string>
15 
16 #include "api/array_view.h"
17 #include "api/rtp_headers.h"
18 #include "api/task_queue/task_queue_base.h"
19 #include "api/units/data_rate.h"
20 #include "api/units/time_delta.h"
21 #include "api/units/timestamp.h"
22 #include "api/video/video_bitrate_allocation.h"
23 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
24 #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
25 #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
26 #include "system_wrappers/include/clock.h"
27 #include "system_wrappers/include/ntp_time.h"
28 
29 namespace webrtc {
30 class ReceiveStatisticsProvider;
31 class Transport;
32 
33 // Interface to watch incoming rtcp packets related to the link in general.
34 // All message handlers have default empty implementation. This way users only
35 // need to implement the ones they are interested in.
36 // All message handles pass `receive_time` parameter, which is receive time
37 // of the rtcp packet that triggered the update.
38 class NetworkLinkRtcpObserver {
39  public:
40   virtual ~NetworkLinkRtcpObserver() = default;
41 
OnTransportFeedback(Timestamp receive_time,const rtcp::TransportFeedback & feedback)42   virtual void OnTransportFeedback(Timestamp receive_time,
43                                    const rtcp::TransportFeedback& feedback) {}
OnReceiverEstimatedMaxBitrate(Timestamp receive_time,DataRate bitrate)44   virtual void OnReceiverEstimatedMaxBitrate(Timestamp receive_time,
45                                              DataRate bitrate) {}
OnReportBlocks(Timestamp receive_time,rtc::ArrayView<const rtcp::ReportBlock> report_blocks)46   virtual void OnReportBlocks(
47       Timestamp receive_time,
48       rtc::ArrayView<const rtcp::ReportBlock> report_blocks) {}
OnRttUpdate(Timestamp receive_time,TimeDelta rtt)49   virtual void OnRttUpdate(Timestamp receive_time, TimeDelta rtt) {}
50 };
51 
52 // Interface to watch incoming rtcp packets by media (rtp) receiver.
53 // All message handlers have default empty implementation. This way users only
54 // need to implement the ones they are interested in.
55 class MediaReceiverRtcpObserver {
56  public:
57   virtual ~MediaReceiverRtcpObserver() = default;
58 
OnSenderReport(uint32_t sender_ssrc,NtpTime ntp_time,uint32_t rtp_time)59   virtual void OnSenderReport(uint32_t sender_ssrc,
60                               NtpTime ntp_time,
61                               uint32_t rtp_time) {}
OnBye(uint32_t sender_ssrc)62   virtual void OnBye(uint32_t sender_ssrc) {}
OnBitrateAllocation(uint32_t sender_ssrc,const VideoBitrateAllocation & allocation)63   virtual void OnBitrateAllocation(uint32_t sender_ssrc,
64                                    const VideoBitrateAllocation& allocation) {}
65 };
66 
67 // Handles RTCP related messages for a single RTP stream (i.e. single SSRC)
68 class RtpStreamRtcpHandler {
69  public:
70   virtual ~RtpStreamRtcpHandler() = default;
71 
72   // Statistic about sent RTP packets to propagate to RTCP sender report.
73   class RtpStats {
74    public:
75     RtpStats() = default;
76     RtpStats(const RtpStats&) = default;
77     RtpStats& operator=(const RtpStats&) = default;
78     ~RtpStats() = default;
79 
num_sent_packets()80     size_t num_sent_packets() const { return num_sent_packets_; }
num_sent_bytes()81     size_t num_sent_bytes() const { return num_sent_bytes_; }
last_capture_time()82     Timestamp last_capture_time() const { return last_capture_time_; }
last_rtp_timestamp()83     uint32_t last_rtp_timestamp() const { return last_rtp_timestamp_; }
last_clock_rate()84     int last_clock_rate() const { return last_clock_rate_; }
85 
set_num_sent_packets(size_t v)86     void set_num_sent_packets(size_t v) { num_sent_packets_ = v; }
set_num_sent_bytes(size_t v)87     void set_num_sent_bytes(size_t v) { num_sent_bytes_ = v; }
set_last_capture_time(Timestamp v)88     void set_last_capture_time(Timestamp v) { last_capture_time_ = v; }
set_last_rtp_timestamp(uint32_t v)89     void set_last_rtp_timestamp(uint32_t v) { last_rtp_timestamp_ = v; }
set_last_clock_rate(int v)90     void set_last_clock_rate(int v) { last_clock_rate_ = v; }
91 
92    private:
93     size_t num_sent_packets_ = 0;
94     size_t num_sent_bytes_ = 0;
95     Timestamp last_capture_time_ = Timestamp::Zero();
96     uint32_t last_rtp_timestamp_ = 0;
97     int last_clock_rate_ = 90'000;
98   };
99   virtual RtpStats SentStats() = 0;
100 
OnNack(uint32_t sender_ssrc,rtc::ArrayView<const uint16_t> sequence_numbers)101   virtual void OnNack(uint32_t sender_ssrc,
102                       rtc::ArrayView<const uint16_t> sequence_numbers) {}
103   virtual void OnFir(uint32_t sender_ssrc) {}
104   virtual void OnPli(uint32_t sender_ssrc) {}
105   virtual void OnReportBlock(uint32_t sender_ssrc,
106                              const rtcp::ReportBlock& report_block) {}
107 };
108 
109 struct RtcpTransceiverConfig {
110   RtcpTransceiverConfig();
111   RtcpTransceiverConfig(const RtcpTransceiverConfig&);
112   RtcpTransceiverConfig& operator=(const RtcpTransceiverConfig&);
113   ~RtcpTransceiverConfig();
114 
115   // Logs the error and returns false if configuration miss key objects or
116   // is inconsistant. May log warnings.
117   bool Validate() const;
118 
119   // Used to prepend all log messages. Can be empty.
120   std::string debug_id;
121 
122   // Ssrc to use as default sender ssrc, e.g. for transport-wide feedbacks.
123   uint32_t feedback_ssrc = 1;
124 
125   // Canonical End-Point Identifier of the local particiapnt.
126   // Defined in rfc3550 section 6 note 2 and section 6.5.1.
127   std::string cname;
128 
129   // Maximum packet size outgoing transport accepts.
130   size_t max_packet_size = 1200;
131 
132   // The clock to use when querying for the NTP time. Should be set.
133   Clock* clock = nullptr;
134 
135   // Transport to send rtcp packets to. Should be set.
136   Transport* outgoing_transport = nullptr;
137 
138   // Queue for scheduling delayed tasks, e.g. sending periodic compound packets.
139   TaskQueueBase* task_queue = nullptr;
140 
141   // Rtcp report block generator for outgoing receiver reports.
142   ReceiveStatisticsProvider* receive_statistics = nullptr;
143 
144   // Should outlive RtcpTransceiver.
145   // Callbacks will be invoked on the `task_queue`.
146   NetworkLinkRtcpObserver* network_link_observer = nullptr;
147 
148   // Configures if sending should
149   //  enforce compound packets: https://tools.ietf.org/html/rfc4585#section-3.1
150   //  or allow reduced size packets: https://tools.ietf.org/html/rfc5506
151   // Receiving accepts both compound and reduced-size packets.
152   RtcpMode rtcp_mode = RtcpMode::kCompound;
153   //
154   // Tuning parameters.
155   //
156   // Initial state if `outgoing_transport` ready to accept packets.
157   bool initial_ready_to_send = true;
158   // Delay before 1st periodic compound packet.
159   TimeDelta initial_report_delay = TimeDelta::Millis(500);
160 
161   // Period between periodic compound packets.
162   TimeDelta report_period = TimeDelta::Seconds(1);
163 
164   //
165   // Flags for features and experiments.
166   //
167   bool schedule_periodic_compound_packets = true;
168   // Estimate RTT as non-sender as described in
169   // https://tools.ietf.org/html/rfc3611#section-4.4 and #section-4.5
170   bool non_sender_rtt_measurement = false;
171 
172   // Reply to incoming RRTR messages so that remote endpoint may estimate RTT as
173   // non-sender as described in https://tools.ietf.org/html/rfc3611#section-4.4
174   // and #section-4.5
175   bool reply_to_non_sender_rtt_measurement = true;
176 
177   // Reply to incoming RRTR messages multiple times, one per sender SSRC, to
178   // support clients that calculate and process RTT per sender SSRC.
179   bool reply_to_non_sender_rtt_mesaurments_on_all_ssrcs = true;
180 
181   // Allows a REMB message to be sent immediately when SetRemb is called without
182   // having to wait for the next compount message to be sent.
183   bool send_remb_on_change = false;
184 };
185 
186 }  // namespace webrtc
187 
188 #endif  // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_CONFIG_H_
189