blob: 5ca6a018290d28d57114d56da09896bd256591fc [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();
35 void PushNACK(WebRtc_UWord16 nack);
36 std::string GetResult();
37
38private:
39 std::ostringstream _stream;
40 int _count;
41 WebRtc_UWord16 _prevNack;
42 bool _consecutive;
43};
44
niklase@google.com470e71d2011-07-07 08:21:25 +000045class RTCPSender
46{
47public:
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000048 RTCPSender(const WebRtc_Word32 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
52 void ChangeUniqueId(const WebRtc_Word32 id);
53
54 WebRtc_Word32 Init();
55
56 WebRtc_Word32 RegisterSendTransport(Transport* outgoingTransport);
57
58 RTCPMethod Status() const;
59 WebRtc_Word32 SetRTCPStatus(const RTCPMethod method);
60
61 bool Sending() const;
62 WebRtc_Word32 SetSendingStatus(const bool enabled); // combine the functions
63
64 WebRtc_Word32 SetNackStatus(const bool enable);
65
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
niklase@google.com470e71d2011-07-07 08:21:25 +000071 void SetSSRC( const WebRtc_UWord32 ssrc);
72
73 WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc);
74
75 WebRtc_Word32 SetCameraDelay(const WebRtc_Word32 delayMS);
76
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000077 WebRtc_Word32 CNAME(char cName[RTCP_CNAME_SIZE]);
78 WebRtc_Word32 SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
80 WebRtc_Word32 AddMixedCNAME(const WebRtc_UWord32 SSRC,
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000081 const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
83 WebRtc_Word32 RemoveMixedCNAME(const WebRtc_UWord32 SSRC);
84
85 WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport);
86
87 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
88
89 WebRtc_UWord32 LastSendReport(WebRtc_UWord32& lastRTCPTime);
90
91 WebRtc_Word32 SendRTCP(const WebRtc_UWord32 rtcpPacketTypeFlags,
pwestin@webrtc.org741da942011-09-20 13:52:04 +000092 const WebRtc_Word32 nackSize = 0,
93 const WebRtc_UWord16* nackList = 0,
pwestin@webrtc.org5e954812012-02-10 12:13:12 +000094 const bool repeat = false,
pwestin@webrtc.org741da942011-09-20 13:52:04 +000095 const WebRtc_UWord64 pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
97 WebRtc_Word32 AddReportBlock(const WebRtc_UWord32 SSRC,
98 const RTCPReportBlock* receiveBlock);
99
100 WebRtc_Word32 RemoveReportBlock(const WebRtc_UWord32 SSRC);
101
102 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000103 * REMB
104 */
105 bool REMB() const;
106
107 WebRtc_Word32 SetREMBStatus(const bool enable);
108
109 WebRtc_Word32 SetREMBData(const WebRtc_UWord32 bitrate,
110 const WebRtc_UWord8 numberOfSSRC,
111 const WebRtc_UWord32* 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
118 WebRtc_Word32 SetTMMBRStatus(const bool enable);
119
120 WebRtc_Word32 SetTMMBN(const TMMBRSet* boundingSet,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000121 const WebRtc_UWord32 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
128 WebRtc_Word32 SetIJStatus(const bool enable);
129
130 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000131 *
132 */
133
134 WebRtc_Word32 SetApplicationSpecificData(const WebRtc_UWord8 subType,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000135 const WebRtc_UWord32 name,
136 const WebRtc_UWord8* data,
137 const WebRtc_UWord16 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
139 WebRtc_Word32 SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
140
141 WebRtc_Word32 SetCSRCs(const WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize],
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000142 const WebRtc_UWord8 arrLength);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
144 WebRtc_Word32 SetCSRCStatus(const bool include);
145
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:
149 WebRtc_Word32 SendToNetwork(const WebRtc_UWord8* dataBuffer,
stefan@webrtc.org439be292012-02-16 14:45:37 +0000150 const WebRtc_UWord16 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
152 void UpdatePacketRate();
153
154 WebRtc_Word32 AddReportBlocks(WebRtc_UWord8* rtcpbuffer,
155 WebRtc_UWord32& pos,
156 WebRtc_UWord8& numberOfReportBlocks,
157 const RTCPReportBlock* received,
158 const WebRtc_UWord32 NTPsec,
159 const WebRtc_UWord32 NTPfrac);
160
161 WebRtc_Word32 BuildSR(WebRtc_UWord8* rtcpbuffer,
162 WebRtc_UWord32& pos,
163 const WebRtc_UWord32 NTPsec,
164 const WebRtc_UWord32 NTPfrac,
165 const RTCPReportBlock* received = NULL);
166
167 WebRtc_Word32 BuildRR(WebRtc_UWord8* rtcpbuffer,
168 WebRtc_UWord32& pos,
169 const WebRtc_UWord32 NTPsec,
170 const WebRtc_UWord32 NTPfrac,
171 const RTCPReportBlock* received = NULL);
172
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000173 WebRtc_Word32 BuildExtendedJitterReport(
174 WebRtc_UWord8* rtcpbuffer,
175 WebRtc_UWord32& pos,
176 const WebRtc_UWord32 jitterTransmissionTimeOffset);
177
niklase@google.com470e71d2011-07-07 08:21:25 +0000178 WebRtc_Word32 BuildSDEC(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
179 WebRtc_Word32 BuildPLI(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000180 WebRtc_Word32 BuildREMB(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
181 WebRtc_Word32 BuildTMMBR(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
niklase@google.com470e71d2011-07-07 08:21:25 +0000182 WebRtc_Word32 BuildTMMBN(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
183 WebRtc_Word32 BuildAPP(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
184 WebRtc_Word32 BuildVoIPMetric(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
185 WebRtc_Word32 BuildBYE(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
186 WebRtc_Word32 BuildFIR(WebRtc_UWord8* rtcpbuffer,
pwestin@webrtc.org5e954812012-02-10 12:13:12 +0000187 WebRtc_UWord32& pos,
188 bool repeat);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189 WebRtc_Word32 BuildSLI(WebRtc_UWord8* rtcpbuffer,
190 WebRtc_UWord32& pos,
191 const WebRtc_UWord8 pictureID);
192 WebRtc_Word32 BuildRPSI(WebRtc_UWord8* rtcpbuffer,
193 WebRtc_UWord32& pos,
194 const WebRtc_UWord64 pictureID,
195 const WebRtc_UWord8 payloadType);
196
197 WebRtc_Word32 BuildNACK(WebRtc_UWord8* rtcpbuffer,
198 WebRtc_UWord32& pos,
199 const WebRtc_Word32 nackSize,
edjee@google.com79b02892013-04-04 19:43:34 +0000200 const WebRtc_UWord16* nackList,
201 std::string* nackString);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
203private:
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000204 WebRtc_Word32 _id;
205 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
pwestin@webrtc.org18530052012-07-03 10:41:54 +0000223 WebRtc_Word64 _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_;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000228 WebRtc_UWord32 _SSRC;
229 WebRtc_UWord32 _remoteSSRC; // SSRC that we receive on our RTP channel
230 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000232 std::map<WebRtc_UWord32, RTCPReportBlock*> _reportBlocks;
233 std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
235 WebRtc_Word32 _cameraDelayMS;
236
237 // Sent
238 WebRtc_UWord32 _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
239 WebRtc_UWord32 _lastRTCPTime[RTCP_NUMBER_OF_SR];
240
241 // send CSRCs
242 WebRtc_UWord8 _CSRCs;
243 WebRtc_UWord32 _CSRC[kRtpCsrcSize];
244 bool _includeCSRCs;
245
246 // Full intra request
247 WebRtc_UWord8 _sequenceNumberFIR;
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000249 // REMB
250 WebRtc_UWord8 _lengthRembSSRC;
251 WebRtc_UWord8 _sizeRembSSRC;
252 WebRtc_UWord32* _rembSSRC;
253 WebRtc_UWord32 _rembBitrate;
254
niklase@google.com470e71d2011-07-07 08:21:25 +0000255 TMMBRHelp _tmmbrHelp;
256 WebRtc_UWord32 _tmmbr_Send;
257 WebRtc_UWord32 _packetOH_Send;
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
259 // APP
260 bool _appSend;
261 WebRtc_UWord8 _appSubType;
262 WebRtc_UWord32 _appName;
263 WebRtc_UWord8* _appData;
264 WebRtc_UWord16 _appLength;
265
266 // XR VoIP metric
267 bool _xrSendVoIPMetric;
268 RTCPVoIPMetric _xrVoIPMetric;
edjee@google.com79b02892013-04-04 19:43:34 +0000269
270 // Counters
271 WebRtc_UWord32 _nackCount;
272 WebRtc_UWord32 _pliCount;
273 WebRtc_UWord32 _fullIntraRequestCount;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274};
275} // namespace webrtc
276
277#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_