2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_
18 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
19 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
20 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
21 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
23 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
24 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
25 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
26 #include "webrtc/typedefs.h"
30 class ModuleRtpRtcpImpl;
33 class NACKStringBuilder
39 void PushNACK(uint16_t nack);
40 std::string GetResult();
43 std::ostringstream _stream;
52 struct FeedbackState {
53 explicit FeedbackState(ModuleRtpRtcpImpl* module);
56 uint8_t send_payload_type;
57 uint32_t frequency_hz;
58 uint32_t packet_count_sent;
59 uint32_t byte_count_sent;
60 uint32_t send_bitrate;
62 uint32_t last_rr_ntp_secs;
63 uint32_t last_rr_ntp_frac;
67 RtcpReceiveTimeInfo last_xr_rr;
69 // Used when generating TMMBR.
70 ModuleRtpRtcpImpl* module;
72 RTCPSender(const int32_t id, const bool audio,
74 ReceiveStatistics* receive_statistics);
75 virtual ~RTCPSender();
77 void ChangeUniqueId(const int32_t id);
81 int32_t RegisterSendTransport(Transport* outgoingTransport);
83 RTCPMethod Status() const;
84 int32_t SetRTCPStatus(const RTCPMethod method);
87 int32_t SetSendingStatus(const FeedbackState& feedback_state,
88 bool enabled); // combine the functions
90 int32_t SetNackStatus(const bool enable);
92 void SetStartTimestamp(uint32_t start_timestamp);
94 void SetLastRtpTime(uint32_t rtp_timestamp,
95 int64_t capture_time_ms);
97 void SetSSRC( const uint32_t ssrc);
99 void SetRemoteSSRC(uint32_t ssrc);
101 int32_t SetCameraDelay(const int32_t delayMS);
103 int32_t CNAME(char cName[RTCP_CNAME_SIZE]);
104 int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]);
106 int32_t AddMixedCNAME(const uint32_t SSRC,
107 const char cName[RTCP_CNAME_SIZE]);
109 int32_t RemoveMixedCNAME(const uint32_t SSRC);
111 uint32_t SendTimeOfSendReport(const uint32_t sendReport);
113 bool SendTimeOfXrRrReport(uint32_t mid_ntp, int64_t* time_ms) const;
115 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
117 uint32_t LastSendReport(uint32_t& lastRTCPTime);
120 const FeedbackState& feedback_state,
121 uint32_t rtcpPacketTypeFlags,
122 int32_t nackSize = 0,
123 const uint16_t* nackList = 0,
125 uint64_t pictureID = 0);
127 int32_t AddExternalReportBlock(
129 const RTCPReportBlock* receiveBlock);
131 int32_t RemoveExternalReportBlock(uint32_t SSRC);
138 int32_t SetREMBStatus(const bool enable);
140 int32_t SetREMBData(const uint32_t bitrate,
141 const uint8_t numberOfSSRC,
142 const uint32_t* SSRC);
149 int32_t SetTMMBRStatus(const bool enable);
151 int32_t SetTMMBN(const TMMBRSet* boundingSet,
152 const uint32_t maxBitrateKbit);
155 * Extended jitter report
159 int32_t SetIJStatus(const bool enable);
165 int32_t SetApplicationSpecificData(const uint8_t subType,
168 const uint16_t length);
170 int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
172 void SendRtcpXrReceiverReferenceTime(bool enable);
174 bool RtcpXrReceiverReferenceTime() const;
176 int32_t SetCSRCs(const uint32_t arrOfCSRC[kRtpCsrcSize],
177 const uint8_t arrLength);
179 int32_t SetCSRCStatus(const bool include);
181 void SetTargetBitrate(unsigned int target_bitrate);
183 void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
186 int32_t SendToNetwork(const uint8_t* dataBuffer, const uint16_t length);
188 void UpdatePacketRate();
190 int32_t WriteAllReportBlocksToBuffer(uint8_t* rtcpbuffer,
192 uint8_t& numberOfReportBlocks,
193 const uint32_t NTPsec,
194 const uint32_t NTPfrac);
196 int32_t WriteReportBlocksToBuffer(
199 const std::map<uint32_t, RTCPReportBlock*>& report_blocks);
201 int32_t AddReportBlock(
203 std::map<uint32_t, RTCPReportBlock*>* report_blocks,
204 const RTCPReportBlock* receiveBlock);
206 bool PrepareReport(const FeedbackState& feedback_state,
207 StreamStatistician* statistician,
208 RTCPReportBlock* report_block,
209 uint32_t* ntp_secs, uint32_t* ntp_frac);
211 int32_t BuildSR(const FeedbackState& feedback_state,
217 int32_t BuildRR(uint8_t* rtcpbuffer,
219 const uint32_t NTPsec,
220 const uint32_t NTPfrac);
223 const FeedbackState& feedback_state,
224 uint32_t packetTypeFlags,
226 const uint16_t* nackList,
229 uint8_t* rtcp_buffer,
232 bool ShouldSendReportBlocks(uint32_t rtcp_packet_type) const;
234 int32_t BuildExtendedJitterReport(
237 const uint32_t jitterTransmissionTimeOffset);
239 int32_t BuildSDEC(uint8_t* rtcpbuffer, int& pos);
240 int32_t BuildPLI(uint8_t* rtcpbuffer, int& pos);
241 int32_t BuildREMB(uint8_t* rtcpbuffer, int& pos);
242 int32_t BuildTMMBR(ModuleRtpRtcpImpl* module,
245 int32_t BuildTMMBN(uint8_t* rtcpbuffer, int& pos);
246 int32_t BuildAPP(uint8_t* rtcpbuffer, int& pos);
247 int32_t BuildVoIPMetric(uint8_t* rtcpbuffer, int& pos);
248 int32_t BuildBYE(uint8_t* rtcpbuffer, int& pos);
249 int32_t BuildFIR(uint8_t* rtcpbuffer, int& pos, bool repeat);
250 int32_t BuildSLI(uint8_t* rtcpbuffer,
252 const uint8_t pictureID);
253 int32_t BuildRPSI(uint8_t* rtcpbuffer,
255 const uint64_t pictureID,
256 const uint8_t payloadType);
258 int32_t BuildNACK(uint8_t* rtcpbuffer,
260 const int32_t nackSize,
261 const uint16_t* nackList,
262 std::string* nackString);
264 int32_t BuildReceiverReferenceTime(uint8_t* buffer,
268 int32_t BuildDlrr(uint8_t* buffer,
270 const RtcpReceiveTimeInfo& info);
278 CriticalSectionWrapper* _criticalSectionTransport;
279 Transport* _cbTransport;
281 CriticalSectionWrapper* _criticalSectionRTCPSender;
290 int64_t _nextTimeToSendRTCP;
292 uint32_t start_timestamp_;
293 uint32_t last_rtp_timestamp_;
294 int64_t last_frame_capture_time_ms_;
296 uint32_t _remoteSSRC; // SSRC that we receive on our RTP channel
297 char _CNAME[RTCP_CNAME_SIZE];
300 ReceiveStatistics* receive_statistics_;
301 std::map<uint32_t, RTCPReportBlock*> internal_report_blocks_;
302 std::map<uint32_t, RTCPReportBlock*> external_report_blocks_;
303 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
305 int32_t _cameraDelayMS;
308 uint32_t _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
309 uint32_t _lastRTCPTime[RTCP_NUMBER_OF_SR];
311 // Sent XR receiver reference time report.
312 // <mid ntp (mid 32 bits of the 64 bits NTP timestamp), send time in ms>.
313 std::map<uint32_t, int64_t> last_xr_rr_;
317 uint32_t _CSRC[kRtpCsrcSize];
320 // Full intra request
321 uint8_t _sequenceNumberFIR;
324 uint8_t _lengthRembSSRC;
325 uint8_t _sizeRembSSRC;
327 uint32_t _rembBitrate;
329 TMMBRHelp _tmmbrHelp;
330 uint32_t _tmmbr_Send;
331 uint32_t _packetOH_Send;
340 // True if sending of XR Receiver reference time report is enabled.
341 bool xrSendReceiverReferenceTimeEnabled_;
344 bool _xrSendVoIPMetric;
345 RTCPVoIPMetric _xrVoIPMetric;
347 RtcpPacketTypeCounter packet_type_counter_;
349 } // namespace webrtc
351 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_