blob: 34a083800ced6044a33eca5a0d722d5c426becc4 [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"
20#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
21#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
22#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
23#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
24#include "webrtc/system_wrappers/interface/scoped_ptr.h"
25#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000028
29class ModuleRtpRtcpImpl;
30
edjee@google.com79b02892013-04-04 19:43:34 +000031class NACKStringBuilder
32{
33public:
34 NACKStringBuilder();
pbos@webrtc.org2f446732013-04-08 11:08:41 +000035 void PushNACK(uint16_t nack);
edjee@google.com79b02892013-04-04 19:43:34 +000036 std::string GetResult();
37
38private:
39 std::ostringstream _stream;
40 int _count;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000041 uint16_t _prevNack;
edjee@google.com79b02892013-04-04 19:43:34 +000042 bool _consecutive;
43};
44
niklase@google.com470e71d2011-07-07 08:21:25 +000045class RTCPSender
46{
47public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000048 RTCPSender(const int32_t id, const bool audio,
stefan@webrtc.org20ed36d2013-01-17 14:01:20 +000049 Clock* clock, ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000050 virtual ~RTCPSender();
51
pbos@webrtc.org2f446732013-04-08 11:08:41 +000052 void ChangeUniqueId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000053
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 int32_t Init();
niklase@google.com470e71d2011-07-07 08:21:25 +000055
pbos@webrtc.org2f446732013-04-08 11:08:41 +000056 int32_t RegisterSendTransport(Transport* outgoingTransport);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
58 RTCPMethod Status() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000059 int32_t SetRTCPStatus(const RTCPMethod method);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61 bool Sending() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000062 int32_t SetSendingStatus(const bool enabled); // combine the functions
niklase@google.com470e71d2011-07-07 08:21:25 +000063
pbos@webrtc.org2f446732013-04-08 11:08:41 +000064 int32_t SetNackStatus(const bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000066 void SetStartTimestamp(uint32_t start_timestamp);
67
68 void SetLastRtpTime(uint32_t rtp_timestamp,
69 int64_t capture_time_ms);
70
pbos@webrtc.org2f446732013-04-08 11:08:41 +000071 void SetSSRC( const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
pbos@webrtc.org2f446732013-04-08 11:08:41 +000073 int32_t SetRemoteSSRC( const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000074
stefan@webrtc.org7da34592013-04-09 14:56:29 +000075 int32_t SetCameraDelay(const int32_t delayMS);
76
pbos@webrtc.org2f446732013-04-08 11:08:41 +000077 int32_t CNAME(char cName[RTCP_CNAME_SIZE]);
78 int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
pbos@webrtc.org2f446732013-04-08 11:08:41 +000080 int32_t AddMixedCNAME(const uint32_t SSRC,
81 const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
pbos@webrtc.org2f446732013-04-08 11:08:41 +000083 int32_t RemoveMixedCNAME(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.org2f446732013-04-08 11:08:41 +000085 uint32_t SendTimeOfSendReport(const uint32_t sendReport);
niklase@google.com470e71d2011-07-07 08:21:25 +000086
87 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
88
pbos@webrtc.org2f446732013-04-08 11:08:41 +000089 uint32_t LastSendReport(uint32_t& lastRTCPTime);
niklase@google.com470e71d2011-07-07 08:21:25 +000090
pbos@webrtc.org2f446732013-04-08 11:08:41 +000091 int32_t SendRTCP(const uint32_t rtcpPacketTypeFlags,
92 const int32_t nackSize = 0,
93 const uint16_t* nackList = 0,
94 const bool repeat = false,
95 const uint64_t pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
pbos@webrtc.org2f446732013-04-08 11:08:41 +000097 int32_t AddReportBlock(const uint32_t SSRC,
98 const RTCPReportBlock* receiveBlock);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000100 int32_t RemoveReportBlock(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
102 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000103 * REMB
104 */
105 bool REMB() const;
106
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000107 int32_t SetREMBStatus(const bool enable);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000108
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000109 int32_t SetREMBData(const uint32_t bitrate,
110 const uint8_t numberOfSSRC,
111 const uint32_t* SSRC);
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000112
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000113 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 * TMMBR
115 */
116 bool TMMBR() const;
117
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000118 int32_t SetTMMBRStatus(const bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000120 int32_t SetTMMBN(const TMMBRSet* boundingSet,
121 const uint32_t maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 /*
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000124 * Extended jitter report
125 */
126 bool IJ() const;
127
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000128 int32_t SetIJStatus(const bool enable);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000129
130 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000131 *
132 */
133
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000134 int32_t SetApplicationSpecificData(const uint8_t subType,
135 const uint32_t name,
136 const uint8_t* data,
137 const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000139 int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000141 int32_t SetCSRCs(const uint32_t arrOfCSRC[kRtpCsrcSize],
142 const uint8_t arrLength);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000144 int32_t SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
stefan@webrtc.org9354cc92012-06-07 08:10:14 +0000146 void SetTargetBitrate(unsigned int target_bitrate);
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000147
niklase@google.com470e71d2011-07-07 08:21:25 +0000148private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000149 int32_t SendToNetwork(const uint8_t* dataBuffer, const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
151 void UpdatePacketRate();
152
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000153 int32_t AddReportBlocks(uint8_t* rtcpbuffer,
154 uint32_t& pos,
155 uint8_t& numberOfReportBlocks,
156 const RTCPReportBlock* received,
157 const uint32_t NTPsec,
158 const uint32_t NTPfrac);
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000160 int32_t BuildSR(uint8_t* rtcpbuffer,
161 uint32_t& pos,
162 const uint32_t NTPsec,
163 const uint32_t NTPfrac,
164 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000166 int32_t BuildRR(uint8_t* rtcpbuffer,
167 uint32_t& pos,
168 const uint32_t NTPsec,
169 const uint32_t NTPfrac,
170 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000172 int32_t BuildExtendedJitterReport(
173 uint8_t* rtcpbuffer,
174 uint32_t& pos,
175 const uint32_t jitterTransmissionTimeOffset);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000176
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000177 int32_t BuildSDEC(uint8_t* rtcpbuffer, uint32_t& pos);
178 int32_t BuildPLI(uint8_t* rtcpbuffer, uint32_t& pos);
179 int32_t BuildREMB(uint8_t* rtcpbuffer, uint32_t& pos);
180 int32_t BuildTMMBR(uint8_t* rtcpbuffer, uint32_t& pos);
181 int32_t BuildTMMBN(uint8_t* rtcpbuffer, uint32_t& pos);
182 int32_t BuildAPP(uint8_t* rtcpbuffer, uint32_t& pos);
183 int32_t BuildVoIPMetric(uint8_t* rtcpbuffer, uint32_t& pos);
184 int32_t BuildBYE(uint8_t* rtcpbuffer, uint32_t& pos);
185 int32_t BuildFIR(uint8_t* rtcpbuffer, uint32_t& pos, bool repeat);
186 int32_t BuildSLI(uint8_t* rtcpbuffer,
187 uint32_t& pos,
188 const uint8_t pictureID);
189 int32_t BuildRPSI(uint8_t* rtcpbuffer,
190 uint32_t& pos,
191 const uint64_t pictureID,
192 const uint8_t payloadType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000194 int32_t BuildNACK(uint8_t* rtcpbuffer,
195 uint32_t& pos,
196 const int32_t nackSize,
197 const uint16_t* nackList,
edjee@google.com79b02892013-04-04 19:43:34 +0000198 std::string* nackString);
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
200private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000201 int32_t _id;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000202 const bool _audio;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000203 Clock* _clock;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000204 RTCPMethod _method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000206 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000208 CriticalSectionWrapper* _criticalSectionTransport;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000209 Transport* _cbTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000211 CriticalSectionWrapper* _criticalSectionRTCPSender;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212 bool _usingNack;
213 bool _sending;
214 bool _sendTMMBN;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000215 bool _REMB;
216 bool _sendREMB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217 bool _TMMBR;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000218 bool _IJ;
niklase@google.com470e71d2011-07-07 08:21:25 +0000219
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000220 int64_t _nextTimeToSendRTCP;
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000222 uint32_t start_timestamp_;
223 uint32_t last_rtp_timestamp_;
224 int64_t last_frame_capture_time_ms_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000225 uint32_t _SSRC;
226 uint32_t _remoteSSRC; // SSRC that we receive on our RTP channel
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000227 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000228
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000229 std::map<uint32_t, RTCPReportBlock*> _reportBlocks;
230 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
stefan@webrtc.org7da34592013-04-09 14:56:29 +0000232 int32_t _cameraDelayMS;
233
niklase@google.com470e71d2011-07-07 08:21:25 +0000234 // Sent
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000235 uint32_t _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
236 uint32_t _lastRTCPTime[RTCP_NUMBER_OF_SR];
niklase@google.com470e71d2011-07-07 08:21:25 +0000237
238 // send CSRCs
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000239 uint8_t _CSRCs;
240 uint32_t _CSRC[kRtpCsrcSize];
niklase@google.com470e71d2011-07-07 08:21:25 +0000241 bool _includeCSRCs;
242
243 // Full intra request
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000244 uint8_t _sequenceNumberFIR;
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000246 // REMB
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000247 uint8_t _lengthRembSSRC;
248 uint8_t _sizeRembSSRC;
249 uint32_t* _rembSSRC;
250 uint32_t _rembBitrate;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000251
niklase@google.com470e71d2011-07-07 08:21:25 +0000252 TMMBRHelp _tmmbrHelp;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000253 uint32_t _tmmbr_Send;
254 uint32_t _packetOH_Send;
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
256 // APP
257 bool _appSend;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000258 uint8_t _appSubType;
259 uint32_t _appName;
260 uint8_t* _appData;
261 uint16_t _appLength;
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
263 // XR VoIP metric
264 bool _xrSendVoIPMetric;
265 RTCPVoIPMetric _xrVoIPMetric;
edjee@google.com79b02892013-04-04 19:43:34 +0000266
267 // Counters
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000268 uint32_t _nackCount;
269 uint32_t _pliCount;
270 uint32_t _fullIntraRequestCount;
niklase@google.com470e71d2011-07-07 08:21:25 +0000271};
272} // namespace webrtc
273
274#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_