blob: 5a0c58fd597b36b82b3a82b2e453008b07194518 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000018#include "typedefs.h"
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000019#include "rtcp_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020#include "rtp_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021#include "rtp_rtcp_defines.h"
stefan@webrtc.org9354cc92012-06-07 08:10:14 +000022#include "scoped_ptr.h"
pwestin@webrtc.org741da942011-09-20 13:52:04 +000023#include "tmmbr_help.h"
stefan@webrtc.org9354cc92012-06-07 08:10:14 +000024#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
25#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.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
pbos@webrtc.org2f446732013-04-08 11:08:41 +000075 int32_t CNAME(char cName[RTCP_CNAME_SIZE]);
76 int32_t SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
pbos@webrtc.org2f446732013-04-08 11:08:41 +000078 int32_t AddMixedCNAME(const uint32_t SSRC,
79 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 RemoveMixedCNAME(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
pbos@webrtc.org2f446732013-04-08 11:08:41 +000083 uint32_t SendTimeOfSendReport(const uint32_t sendReport);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
85 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
86
pbos@webrtc.org2f446732013-04-08 11:08:41 +000087 uint32_t LastSendReport(uint32_t& lastRTCPTime);
niklase@google.com470e71d2011-07-07 08:21:25 +000088
pbos@webrtc.org2f446732013-04-08 11:08:41 +000089 int32_t SendRTCP(const uint32_t rtcpPacketTypeFlags,
90 const int32_t nackSize = 0,
91 const uint16_t* nackList = 0,
92 const bool repeat = false,
93 const uint64_t pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000094
pbos@webrtc.org2f446732013-04-08 11:08:41 +000095 int32_t AddReportBlock(const uint32_t SSRC,
96 const RTCPReportBlock* receiveBlock);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
pbos@webrtc.org2f446732013-04-08 11:08:41 +000098 int32_t RemoveReportBlock(const uint32_t SSRC);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
100 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000101 * REMB
102 */
103 bool REMB() const;
104
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000105 int32_t SetREMBStatus(const bool enable);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000106
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000107 int32_t SetREMBData(const uint32_t bitrate,
108 const uint8_t numberOfSSRC,
109 const uint32_t* SSRC);
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000110
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000111 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 * TMMBR
113 */
114 bool TMMBR() const;
115
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000116 int32_t SetTMMBRStatus(const bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000118 int32_t SetTMMBN(const TMMBRSet* boundingSet,
119 const uint32_t maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
niklase@google.com470e71d2011-07-07 08:21:25 +0000121 /*
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000122 * Extended jitter report
123 */
124 bool IJ() const;
125
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000126 int32_t SetIJStatus(const bool enable);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000127
128 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000129 *
130 */
131
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000132 int32_t SetApplicationSpecificData(const uint8_t subType,
133 const uint32_t name,
134 const uint8_t* data,
135 const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000137 int32_t SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000139 int32_t SetCSRCs(const uint32_t arrOfCSRC[kRtpCsrcSize],
140 const uint8_t arrLength);
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000142 int32_t SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
stefan@webrtc.org9354cc92012-06-07 08:10:14 +0000144 void SetTargetBitrate(unsigned int target_bitrate);
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000145
niklase@google.com470e71d2011-07-07 08:21:25 +0000146private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000147 int32_t SendToNetwork(const uint8_t* dataBuffer, const uint16_t length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
149 void UpdatePacketRate();
150
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000151 int32_t AddReportBlocks(uint8_t* rtcpbuffer,
152 uint32_t& pos,
153 uint8_t& numberOfReportBlocks,
154 const RTCPReportBlock* received,
155 const uint32_t NTPsec,
156 const uint32_t NTPfrac);
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000158 int32_t BuildSR(uint8_t* rtcpbuffer,
159 uint32_t& pos,
160 const uint32_t NTPsec,
161 const uint32_t NTPfrac,
162 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000164 int32_t BuildRR(uint8_t* rtcpbuffer,
165 uint32_t& pos,
166 const uint32_t NTPsec,
167 const uint32_t NTPfrac,
168 const RTCPReportBlock* received = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000170 int32_t BuildExtendedJitterReport(
171 uint8_t* rtcpbuffer,
172 uint32_t& pos,
173 const uint32_t jitterTransmissionTimeOffset);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000174
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000175 int32_t BuildSDEC(uint8_t* rtcpbuffer, uint32_t& pos);
176 int32_t BuildPLI(uint8_t* rtcpbuffer, uint32_t& pos);
177 int32_t BuildREMB(uint8_t* rtcpbuffer, uint32_t& pos);
178 int32_t BuildTMMBR(uint8_t* rtcpbuffer, uint32_t& pos);
179 int32_t BuildTMMBN(uint8_t* rtcpbuffer, uint32_t& pos);
180 int32_t BuildAPP(uint8_t* rtcpbuffer, uint32_t& pos);
181 int32_t BuildVoIPMetric(uint8_t* rtcpbuffer, uint32_t& pos);
182 int32_t BuildBYE(uint8_t* rtcpbuffer, uint32_t& pos);
183 int32_t BuildFIR(uint8_t* rtcpbuffer, uint32_t& pos, bool repeat);
184 int32_t BuildSLI(uint8_t* rtcpbuffer,
185 uint32_t& pos,
186 const uint8_t pictureID);
187 int32_t BuildRPSI(uint8_t* rtcpbuffer,
188 uint32_t& pos,
189 const uint64_t pictureID,
190 const uint8_t payloadType);
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000192 int32_t BuildNACK(uint8_t* rtcpbuffer,
193 uint32_t& pos,
194 const int32_t nackSize,
195 const uint16_t* nackList,
edjee@google.com79b02892013-04-04 19:43:34 +0000196 std::string* nackString);
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
stefan@webrtc.orgafcc6102013-04-09 13:37:40 +0000198 bool RtpTimestampNow(uint32_t ntp_secs_now, uint32_t ntp_fracs_now,
199 uint32_t* timestamp_now) const;
200
niklase@google.com470e71d2011-07-07 08:21:25 +0000201private:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000202 int32_t _id;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000203 const bool _audio;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000204 Clock* _clock;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000205 RTCPMethod _method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000207 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000209 CriticalSectionWrapper* _criticalSectionTransport;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000210 Transport* _cbTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000212 CriticalSectionWrapper* _criticalSectionRTCPSender;
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 bool _usingNack;
214 bool _sending;
215 bool _sendTMMBN;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000216 bool _REMB;
217 bool _sendREMB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000218 bool _TMMBR;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000219 bool _IJ;
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000221 int64_t _nextTimeToSendRTCP;
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000223 uint32_t start_timestamp_;
224 uint32_t last_rtp_timestamp_;
225 int64_t last_frame_capture_time_ms_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000226 uint32_t _SSRC;
227 uint32_t _remoteSSRC; // SSRC that we receive on our RTP channel
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000228 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000230 std::map<uint32_t, RTCPReportBlock*> _reportBlocks;
231 std::map<uint32_t, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 // Sent
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000234 uint32_t _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
235 uint32_t _lastRTCPTime[RTCP_NUMBER_OF_SR];
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
237 // send CSRCs
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000238 uint8_t _CSRCs;
239 uint32_t _CSRC[kRtpCsrcSize];
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 bool _includeCSRCs;
241
242 // Full intra request
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000243 uint8_t _sequenceNumberFIR;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000245 // REMB
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000246 uint8_t _lengthRembSSRC;
247 uint8_t _sizeRembSSRC;
248 uint32_t* _rembSSRC;
249 uint32_t _rembBitrate;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000250
niklase@google.com470e71d2011-07-07 08:21:25 +0000251 TMMBRHelp _tmmbrHelp;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000252 uint32_t _tmmbr_Send;
253 uint32_t _packetOH_Send;
niklase@google.com470e71d2011-07-07 08:21:25 +0000254
255 // APP
256 bool _appSend;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000257 uint8_t _appSubType;
258 uint32_t _appName;
259 uint8_t* _appData;
260 uint16_t _appLength;
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
262 // XR VoIP metric
263 bool _xrSendVoIPMetric;
264 RTCPVoIPMetric _xrVoIPMetric;
edjee@google.com79b02892013-04-04 19:43:34 +0000265
266 // Counters
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000267 uint32_t _nackCount;
268 uint32_t _pliCount;
269 uint32_t _fullIntraRequestCount;
niklase@google.com470e71d2011-07-07 08:21:25 +0000270};
271} // namespace webrtc
272
273#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_