blob: fec0b289427040afeff176a878825c8f9c71434f [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>
15
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "typedefs.h"
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000017#include "rtcp_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018#include "rtp_utility.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019#include "rtp_rtcp_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020#include "remote_rate_control.h"
pwestin@webrtc.org741da942011-09-20 13:52:04 +000021#include "tmmbr_help.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000024
25class ModuleRtpRtcpImpl;
26
niklase@google.com470e71d2011-07-07 08:21:25 +000027class RTCPSender
28{
29public:
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000030 RTCPSender(const WebRtc_Word32 id, const bool audio,
31 RtpRtcpClock* clock, ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000032 virtual ~RTCPSender();
33
34 void ChangeUniqueId(const WebRtc_Word32 id);
35
36 WebRtc_Word32 Init();
37
38 WebRtc_Word32 RegisterSendTransport(Transport* outgoingTransport);
39
40 RTCPMethod Status() const;
41 WebRtc_Word32 SetRTCPStatus(const RTCPMethod method);
42
43 bool Sending() const;
44 WebRtc_Word32 SetSendingStatus(const bool enabled); // combine the functions
45
46 WebRtc_Word32 SetNackStatus(const bool enable);
47
48 void SetSSRC( const WebRtc_UWord32 ssrc);
49
50 WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc);
51
52 WebRtc_Word32 SetCameraDelay(const WebRtc_Word32 delayMS);
53
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000054 WebRtc_Word32 CNAME(char cName[RTCP_CNAME_SIZE]);
55 WebRtc_Word32 SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57 WebRtc_Word32 AddMixedCNAME(const WebRtc_UWord32 SSRC,
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000058 const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
60 WebRtc_Word32 RemoveMixedCNAME(const WebRtc_UWord32 SSRC);
61
62 WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport);
63
64 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
65
66 WebRtc_UWord32 LastSendReport(WebRtc_UWord32& lastRTCPTime);
67
68 WebRtc_Word32 SendRTCP(const WebRtc_UWord32 rtcpPacketTypeFlags,
pwestin@webrtc.org741da942011-09-20 13:52:04 +000069 const WebRtc_Word32 nackSize = 0,
70 const WebRtc_UWord16* nackList = 0,
71 const WebRtc_UWord32 RTT = 0,
72 const WebRtc_UWord64 pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000073
74 WebRtc_Word32 AddReportBlock(const WebRtc_UWord32 SSRC,
75 const RTCPReportBlock* receiveBlock);
76
77 WebRtc_Word32 RemoveReportBlock(const WebRtc_UWord32 SSRC);
78
79 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +000080 * REMB
81 */
82 bool REMB() const;
83
84 WebRtc_Word32 SetREMBStatus(const bool enable);
85
86 WebRtc_Word32 SetREMBData(const WebRtc_UWord32 bitrate,
87 const WebRtc_UWord8 numberOfSSRC,
88 const WebRtc_UWord32* SSRC);
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +000089
90 bool SetRemoteBitrateObserver(RtpRemoteBitrateObserver* observer);
91
92 void UpdateRemoteBitrateEstimate(unsigned int target_bitrate);
93
pwestin@webrtc.org741da942011-09-20 13:52:04 +000094 /*
niklase@google.com470e71d2011-07-07 08:21:25 +000095 * TMMBR
96 */
97 bool TMMBR() const;
98
99 WebRtc_Word32 SetTMMBRStatus(const bool enable);
100
101 WebRtc_Word32 SetTMMBN(const TMMBRSet* boundingSet,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000102 const WebRtc_UWord32 maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104 WebRtc_Word32 RequestTMMBR(const WebRtc_UWord32 estimatedBW,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000105 const WebRtc_UWord32 packetOH);
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107 /*
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000108 * Extended jitter report
109 */
110 bool IJ() const;
111
112 WebRtc_Word32 SetIJStatus(const bool enable);
113
114 /*
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 *
116 */
117
118 WebRtc_Word32 SetApplicationSpecificData(const WebRtc_UWord8 subType,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000119 const WebRtc_UWord32 name,
120 const WebRtc_UWord8* data,
121 const WebRtc_UWord16 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
123 WebRtc_Word32 SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric);
124
125 WebRtc_Word32 SetCSRCs(const WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize],
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000126 const WebRtc_UWord8 arrLength);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
128 WebRtc_Word32 SetCSRCStatus(const bool include);
129
130 /*
131 * New bandwidth estimation
132 */
133
134 RateControlRegion UpdateOverUseState(const RateControlInput& rateControlInput, bool& firstOverUse);
135
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000136 WebRtc_UWord32 CalculateNewTargetBitrate(WebRtc_UWord32 RTT);
137
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000138 // Returns true if there is a valid estimate of the incoming bitrate, false
139 // otherwise.
140 bool ValidBitrateEstimate();
141
niklase@google.com470e71d2011-07-07 08:21:25 +0000142private:
143 WebRtc_Word32 SendToNetwork(const WebRtc_UWord8* dataBuffer,
144 const WebRtc_UWord16 length);
145
146 void UpdatePacketRate();
147
148 WebRtc_Word32 AddReportBlocks(WebRtc_UWord8* rtcpbuffer,
149 WebRtc_UWord32& pos,
150 WebRtc_UWord8& numberOfReportBlocks,
151 const RTCPReportBlock* received,
152 const WebRtc_UWord32 NTPsec,
153 const WebRtc_UWord32 NTPfrac);
154
155 WebRtc_Word32 BuildSR(WebRtc_UWord8* rtcpbuffer,
156 WebRtc_UWord32& pos,
157 const WebRtc_UWord32 NTPsec,
158 const WebRtc_UWord32 NTPfrac,
159 const RTCPReportBlock* received = NULL);
160
161 WebRtc_Word32 BuildRR(WebRtc_UWord8* rtcpbuffer,
162 WebRtc_UWord32& pos,
163 const WebRtc_UWord32 NTPsec,
164 const WebRtc_UWord32 NTPfrac,
165 const RTCPReportBlock* received = NULL);
166
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000167 WebRtc_Word32 BuildExtendedJitterReport(
168 WebRtc_UWord8* rtcpbuffer,
169 WebRtc_UWord32& pos,
170 const WebRtc_UWord32 jitterTransmissionTimeOffset);
171
niklase@google.com470e71d2011-07-07 08:21:25 +0000172 WebRtc_Word32 BuildSDEC(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
173 WebRtc_Word32 BuildPLI(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000174 WebRtc_Word32 BuildREMB(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
175 WebRtc_Word32 BuildTMMBR(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
niklase@google.com470e71d2011-07-07 08:21:25 +0000176 WebRtc_Word32 BuildTMMBN(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
177 WebRtc_Word32 BuildAPP(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
178 WebRtc_Word32 BuildVoIPMetric(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
179 WebRtc_Word32 BuildBYE(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
180 WebRtc_Word32 BuildFIR(WebRtc_UWord8* rtcpbuffer,
181 WebRtc_UWord32& pos,
182 const WebRtc_UWord32 RTT);
183 WebRtc_Word32 BuildSLI(WebRtc_UWord8* rtcpbuffer,
184 WebRtc_UWord32& pos,
185 const WebRtc_UWord8 pictureID);
186 WebRtc_Word32 BuildRPSI(WebRtc_UWord8* rtcpbuffer,
187 WebRtc_UWord32& pos,
188 const WebRtc_UWord64 pictureID,
189 const WebRtc_UWord8 payloadType);
190
191 WebRtc_Word32 BuildNACK(WebRtc_UWord8* rtcpbuffer,
192 WebRtc_UWord32& pos,
193 const WebRtc_Word32 nackSize,
194 const WebRtc_UWord16* nackList);
195
196private:
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000197 WebRtc_Word32 _id;
198 const bool _audio;
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +0000199 RtpRtcpClock& _clock;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000200 RTCPMethod _method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000202 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000204 CriticalSectionWrapper* _criticalSectionTransport;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000205 Transport* _cbTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000207 CriticalSectionWrapper* _criticalSectionRTCPSender;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208 bool _usingNack;
209 bool _sending;
210 bool _sendTMMBN;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000211 bool _REMB;
212 bool _sendREMB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000213 bool _TMMBR;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000214 bool _IJ;
niklase@google.com470e71d2011-07-07 08:21:25 +0000215
216 WebRtc_UWord32 _nextTimeToSendRTCP;
217
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000218 WebRtc_UWord32 _SSRC;
219 WebRtc_UWord32 _remoteSSRC; // SSRC that we receive on our RTP channel
220 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000222 std::map<WebRtc_UWord32, RTCPReportBlock*> _reportBlocks;
223 std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000224
225 WebRtc_Word32 _cameraDelayMS;
226
227 // Sent
228 WebRtc_UWord32 _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
229 WebRtc_UWord32 _lastRTCPTime[RTCP_NUMBER_OF_SR];
230
231 // send CSRCs
232 WebRtc_UWord8 _CSRCs;
233 WebRtc_UWord32 _CSRC[kRtpCsrcSize];
234 bool _includeCSRCs;
235
236 // Full intra request
237 WebRtc_UWord8 _sequenceNumberFIR;
238 WebRtc_UWord32 _lastTimeFIR;
239
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000240 // REMB
241 WebRtc_UWord8 _lengthRembSSRC;
242 WebRtc_UWord8 _sizeRembSSRC;
243 WebRtc_UWord32* _rembSSRC;
244 WebRtc_UWord32 _rembBitrate;
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000245 RtpRemoteBitrateObserver* _bitrate_observer;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000246
niklase@google.com470e71d2011-07-07 08:21:25 +0000247 TMMBRHelp _tmmbrHelp;
248 WebRtc_UWord32 _tmmbr_Send;
249 WebRtc_UWord32 _packetOH_Send;
250 RemoteRateControl _remoteRateControl;
251
252 // APP
253 bool _appSend;
254 WebRtc_UWord8 _appSubType;
255 WebRtc_UWord32 _appName;
256 WebRtc_UWord8* _appData;
257 WebRtc_UWord16 _appLength;
258
259 // XR VoIP metric
260 bool _xrSendVoIPMetric;
261 RTCPVoIPMetric _xrVoIPMetric;
262};
263} // namespace webrtc
264
265#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_