blob: 06c07f44833308de454cb241efe6125e1b59956f [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_
13
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000014#include <map>
edjee@google.com79b02892013-04-04 19:43:34 +000015#include <sstream>
16#include <string>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000017
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000018#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
19#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000020#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000021#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"
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000029
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000030class ModuleRtpRtcpImpl;
pwestin@webrtc.org741da942011-09-20 13:52:04 +000031
edjee@google.com79b02892013-04-04 19:43:34 +000032class NACKStringBuilder
33{
34public:
35 NACKStringBuilder();
pbos@webrtc.org2f446732013-04-08 11:08:41 +000036 void PushNACK(uint16_t nack);
edjee@google.com79b02892013-04-04 19:43:34 +000037 std::string GetResult();
38
39private:
40 std::ostringstream _stream;
41 int _count;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000042 uint16_t _prevNack;
edjee@google.com79b02892013-04-04 19:43:34 +000043 bool _consecutive;
44};
45
niklase@google.com470e71d2011-07-07 08:21:25 +000046class RTCPSender
47{
48public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000049 RTCPSender(const int32_t id, const bool audio,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +000050 Clock* clock, ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000051 virtual ~RTCPSender();
52
pbos@webrtc.org2f446732013-04-08 11:08:41 +000053 void ChangeUniqueId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pbos@webrtc.org2f446732013-04-08 11:08:41 +000055 int32_t Init();
niklase@google.com470e71d2011-07-07 08:21:25 +000056
pbos@webrtc.org2f446732013-04-08 11:08:41 +000057 int32_t RegisterSendTransport(Transport* outgoingTransport);
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59 RTCPMethod Status() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000060 int32_t SetRTCPStatus(const RTCPMethod method);
niklase@google.com470e71d2011-07-07 08:21:25 +000061
62 bool Sending() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000063 int32_t SetSendingStatus(const bool enabled); // combine the functions
niklase@google.com470e71d2011-07-07 08:21:25 +000064
pbos@webrtc.org2f446732013-04-08 11:08:41 +000065 int32_t SetNackStatus(const bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000066
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000067 void SetStartTimestamp(uint32_t start_timestamp);
68
69 void SetLastRtpTime(uint32_t rtp_timestamp,
70 int64_t capture_time_ms);
71
pbos@webrtc.org2f446732013-04-08 11:08:41 +000072 void SetSSRC( const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000073
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000074 void SetRemoteSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
stefan@webrtc.org7da34592013-04-09 14:56:29 +000076 int32_t SetCameraDelay(const int32_t delayMS);
77
pbos@webrtc.org2f446732013-04-08 11:08:41 +000078 int32_t CNAME(char cName[RTCP_CNAME_SIZE]);
79 int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
pbos@webrtc.org2f446732013-04-08 11:08:41 +000081 int32_t AddMixedCNAME(const uint32_t SSRC,
82 const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
pbos@webrtc.org2f446732013-04-08 11:08:41 +000084 int32_t RemoveMixedCNAME(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +000085
pbos@webrtc.org2f446732013-04-08 11:08:41 +000086 uint32_t SendTimeOfSendReport(const uint32_t sendReport);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
88 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
89
pbos@webrtc.org2f446732013-04-08 11:08:41 +000090 uint32_t LastSendReport(uint32_t& lastRTCPTime);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000092 int32_t SendRTCP(
93 uint32_t rtcpPacketTypeFlags,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +000094 const ReceiveStatistics::RtpReceiveStatistics* receive_stats,
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000095 int32_t nackSize = 0,
96 const uint16_t* nackList = 0,
97 bool repeat = false,
98 uint64_t pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000100 int32_t AddReportBlock(const uint32_t SSRC,
101 const RTCPReportBlock* receiveBlock);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000103 int32_t RemoveReportBlock(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
105 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000106 * REMB
107 */
108 bool REMB() const;
109
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000110 int32_t SetREMBStatus(const bool enable);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000111
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000112 int32_t SetREMBData(const uint32_t bitrate,
113 const uint8_t numberOfSSRC,
114 const uint32_t* SSRC);
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000115
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000116 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 * TMMBR
118 */
119 bool TMMBR() const;
120
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000121 int32_t SetTMMBRStatus(const bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000123 int32_t SetTMMBN(const TMMBRSet* boundingSet,
124 const uint32_t maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
niklase@google.com470e71d2011-07-07 08:21:25 +0000126 /*
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000127 * Extended jitter report
128 */
129 bool IJ() const;
130
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000131 int32_t SetIJStatus(const bool enable);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000132
133 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 *
135 */
136
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000137 int32_t SetApplicationSpecificData(const uint8_t subType,
138 const uint32_t name,
139 const uint8_t* data,
140 const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000142 int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000144 int32_t SetCSRCs(const uint32_t arrOfCSRC[kRtpCsrcSize],
145 const uint8_t arrLength);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000147 int32_t SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
stefan@webrtc.org9354cc92012-06-07 08:10:14 +0000149 void SetTargetBitrate(unsigned int target_bitrate);
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000150
niklase@google.com470e71d2011-07-07 08:21:25 +0000151private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000152 int32_t SendToNetwork(const uint8_t* dataBuffer, const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
154 void UpdatePacketRate();
155
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000156 int32_t AddReportBlocks(uint8_t* rtcpbuffer,
157 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000158 uint8_t& numberOfReportBlocks,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000159 const RTCPReportBlock* received,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000160 const uint32_t NTPsec,
161 const uint32_t NTPfrac);
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000163 int32_t BuildSR(uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000164 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000165 const uint32_t NTPsec,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000166 const uint32_t NTPfrac,
167 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000169 int32_t BuildRR(uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000170 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000171 const uint32_t NTPsec,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000172 const uint32_t NTPfrac,
173 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000175 int32_t BuildExtendedJitterReport(
176 uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000177 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000178 const uint32_t jitterTransmissionTimeOffset);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000179
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000180 int32_t BuildSDEC(uint8_t* rtcpbuffer, uint32_t& pos);
181 int32_t BuildPLI(uint8_t* rtcpbuffer, uint32_t& pos);
182 int32_t BuildREMB(uint8_t* rtcpbuffer, uint32_t& pos);
183 int32_t BuildTMMBR(uint8_t* rtcpbuffer, uint32_t& pos);
184 int32_t BuildTMMBN(uint8_t* rtcpbuffer, uint32_t& pos);
185 int32_t BuildAPP(uint8_t* rtcpbuffer, uint32_t& pos);
186 int32_t BuildVoIPMetric(uint8_t* rtcpbuffer, uint32_t& pos);
187 int32_t BuildBYE(uint8_t* rtcpbuffer, uint32_t& pos);
188 int32_t BuildFIR(uint8_t* rtcpbuffer, uint32_t& pos, bool repeat);
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000189 int32_t BuildSLI(uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000190 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000191 const uint8_t pictureID);
192 int32_t BuildRPSI(uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000193 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000194 const uint64_t pictureID,
195 const uint8_t payloadType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000197 int32_t BuildNACK(uint8_t* rtcpbuffer,
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000198 uint32_t& pos,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000199 const int32_t nackSize,
200 const uint16_t* nackList,
edjee@google.com79b02892013-04-04 19:43:34 +0000201 std::string* nackString);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
203private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000204 int32_t _id;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000205 const bool _audio;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000206 Clock* _clock;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000207 RTCPMethod _method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000209 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000211 CriticalSectionWrapper* _criticalSectionTransport;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000212 Transport* _cbTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +0000213
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000214 CriticalSectionWrapper* _criticalSectionRTCPSender;
niklase@google.com470e71d2011-07-07 08:21:25 +0000215 bool _usingNack;
216 bool _sending;
217 bool _sendTMMBN;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000218 bool _REMB;
219 bool _sendREMB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000220 bool _TMMBR;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000221 bool _IJ;
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000223 int64_t _nextTimeToSendRTCP;
niklase@google.com470e71d2011-07-07 08:21:25 +0000224
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000225 uint32_t start_timestamp_;
226 uint32_t last_rtp_timestamp_;
227 int64_t last_frame_capture_time_ms_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000228 uint32_t _SSRC;
229 uint32_t _remoteSSRC; // SSRC that we receive on our RTP channel
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000230 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
elham@webrtc.orgb7eda432013-07-15 21:08:27 +0000232 std::map<uint32_t, RTCPReportBlock*> _reportBlocks;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000233 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
stefan@webrtc.org7da34592013-04-09 14:56:29 +0000235 int32_t _cameraDelayMS;
236
niklase@google.com470e71d2011-07-07 08:21:25 +0000237 // Sent
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000238 uint32_t _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
239 uint32_t _lastRTCPTime[RTCP_NUMBER_OF_SR];
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
241 // send CSRCs
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000242 uint8_t _CSRCs;
243 uint32_t _CSRC[kRtpCsrcSize];
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 bool _includeCSRCs;
245
246 // Full intra request
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000247 uint8_t _sequenceNumberFIR;
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000249 // REMB
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000250 uint8_t _lengthRembSSRC;
251 uint8_t _sizeRembSSRC;
252 uint32_t* _rembSSRC;
253 uint32_t _rembBitrate;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000254
niklase@google.com470e71d2011-07-07 08:21:25 +0000255 TMMBRHelp _tmmbrHelp;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000256 uint32_t _tmmbr_Send;
257 uint32_t _packetOH_Send;
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
259 // APP
260 bool _appSend;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000261 uint8_t _appSubType;
262 uint32_t _appName;
263 uint8_t* _appData;
264 uint16_t _appLength;
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
266 // XR VoIP metric
267 bool _xrSendVoIPMetric;
268 RTCPVoIPMetric _xrVoIPMetric;
edjee@google.com79b02892013-04-04 19:43:34 +0000269
270 // Counters
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000271 uint32_t _nackCount;
272 uint32_t _pliCount;
273 uint32_t _fullIntraRequestCount;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000275} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
277#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_