blob: b6063725437882ebf416020ec03ab483f4d7b1fa [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"
stefan@webrtc.org9354cc92012-06-07 08:10:14 +000020#include "scoped_ptr.h"
pwestin@webrtc.org741da942011-09-20 13:52:04 +000021#include "tmmbr_help.h"
stefan@webrtc.org9354cc92012-06-07 08:10:14 +000022#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
23#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25namespace webrtc {
pwestin@webrtc.org741da942011-09-20 13:52:04 +000026
27class ModuleRtpRtcpImpl;
28
niklase@google.com470e71d2011-07-07 08:21:25 +000029class RTCPSender
30{
31public:
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +000032 RTCPSender(const WebRtc_Word32 id, const bool audio,
33 RtpRtcpClock* clock, ModuleRtpRtcpImpl* owner);
niklase@google.com470e71d2011-07-07 08:21:25 +000034 virtual ~RTCPSender();
35
36 void ChangeUniqueId(const WebRtc_Word32 id);
37
38 WebRtc_Word32 Init();
39
40 WebRtc_Word32 RegisterSendTransport(Transport* outgoingTransport);
41
42 RTCPMethod Status() const;
43 WebRtc_Word32 SetRTCPStatus(const RTCPMethod method);
44
45 bool Sending() const;
46 WebRtc_Word32 SetSendingStatus(const bool enabled); // combine the functions
47
48 WebRtc_Word32 SetNackStatus(const bool enable);
49
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000050 void SetStartTimestamp(uint32_t start_timestamp);
51
52 void SetLastRtpTime(uint32_t rtp_timestamp,
53 int64_t capture_time_ms);
54
niklase@google.com470e71d2011-07-07 08:21:25 +000055 void SetSSRC( const WebRtc_UWord32 ssrc);
56
57 WebRtc_Word32 SetRemoteSSRC( const WebRtc_UWord32 ssrc);
58
59 WebRtc_Word32 SetCameraDelay(const WebRtc_Word32 delayMS);
60
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000061 WebRtc_Word32 CNAME(char cName[RTCP_CNAME_SIZE]);
62 WebRtc_Word32 SetCNAME(const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
64 WebRtc_Word32 AddMixedCNAME(const WebRtc_UWord32 SSRC,
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +000065 const char cName[RTCP_CNAME_SIZE]);
niklase@google.com470e71d2011-07-07 08:21:25 +000066
67 WebRtc_Word32 RemoveMixedCNAME(const WebRtc_UWord32 SSRC);
68
69 WebRtc_UWord32 SendTimeOfSendReport(const WebRtc_UWord32 sendReport);
70
71 bool TimeToSendRTCPReport(const bool sendKeyframeBeforeRTP = false) const;
72
73 WebRtc_UWord32 LastSendReport(WebRtc_UWord32& lastRTCPTime);
74
75 WebRtc_Word32 SendRTCP(const WebRtc_UWord32 rtcpPacketTypeFlags,
pwestin@webrtc.org741da942011-09-20 13:52:04 +000076 const WebRtc_Word32 nackSize = 0,
77 const WebRtc_UWord16* nackList = 0,
pwestin@webrtc.org5e954812012-02-10 12:13:12 +000078 const bool repeat = false,
pwestin@webrtc.org741da942011-09-20 13:52:04 +000079 const WebRtc_UWord64 pictureID = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
81 WebRtc_Word32 AddReportBlock(const WebRtc_UWord32 SSRC,
82 const RTCPReportBlock* receiveBlock);
83
84 WebRtc_Word32 RemoveReportBlock(const WebRtc_UWord32 SSRC);
85
86 /*
pwestin@webrtc.org741da942011-09-20 13:52:04 +000087 * REMB
88 */
89 bool REMB() const;
90
91 WebRtc_Word32 SetREMBStatus(const bool enable);
92
93 WebRtc_Word32 SetREMBData(const WebRtc_UWord32 bitrate,
94 const WebRtc_UWord8 numberOfSSRC,
95 const WebRtc_UWord32* SSRC);
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +000096
pwestin@webrtc.org741da942011-09-20 13:52:04 +000097 /*
niklase@google.com470e71d2011-07-07 08:21:25 +000098 * TMMBR
99 */
100 bool TMMBR() const;
101
102 WebRtc_Word32 SetTMMBRStatus(const bool enable);
103
104 WebRtc_Word32 SetTMMBN(const TMMBRSet* boundingSet,
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000105 const WebRtc_UWord32 maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 /*
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
stefan@webrtc.org9354cc92012-06-07 08:10:14 +0000130 void SetTargetBitrate(unsigned int target_bitrate);
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000131
niklase@google.com470e71d2011-07-07 08:21:25 +0000132private:
133 WebRtc_Word32 SendToNetwork(const WebRtc_UWord8* dataBuffer,
stefan@webrtc.org439be292012-02-16 14:45:37 +0000134 const WebRtc_UWord16 length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
136 void UpdatePacketRate();
137
138 WebRtc_Word32 AddReportBlocks(WebRtc_UWord8* rtcpbuffer,
139 WebRtc_UWord32& pos,
140 WebRtc_UWord8& numberOfReportBlocks,
141 const RTCPReportBlock* received,
142 const WebRtc_UWord32 NTPsec,
143 const WebRtc_UWord32 NTPfrac);
144
145 WebRtc_Word32 BuildSR(WebRtc_UWord8* rtcpbuffer,
146 WebRtc_UWord32& pos,
147 const WebRtc_UWord32 NTPsec,
148 const WebRtc_UWord32 NTPfrac,
149 const RTCPReportBlock* received = NULL);
150
151 WebRtc_Word32 BuildRR(WebRtc_UWord8* rtcpbuffer,
152 WebRtc_UWord32& pos,
153 const WebRtc_UWord32 NTPsec,
154 const WebRtc_UWord32 NTPfrac,
155 const RTCPReportBlock* received = NULL);
156
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000157 WebRtc_Word32 BuildExtendedJitterReport(
158 WebRtc_UWord8* rtcpbuffer,
159 WebRtc_UWord32& pos,
160 const WebRtc_UWord32 jitterTransmissionTimeOffset);
161
niklase@google.com470e71d2011-07-07 08:21:25 +0000162 WebRtc_Word32 BuildSDEC(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
163 WebRtc_Word32 BuildPLI(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000164 WebRtc_Word32 BuildREMB(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
165 WebRtc_Word32 BuildTMMBR(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
niklase@google.com470e71d2011-07-07 08:21:25 +0000166 WebRtc_Word32 BuildTMMBN(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
167 WebRtc_Word32 BuildAPP(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
168 WebRtc_Word32 BuildVoIPMetric(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
169 WebRtc_Word32 BuildBYE(WebRtc_UWord8* rtcpbuffer, WebRtc_UWord32& pos);
170 WebRtc_Word32 BuildFIR(WebRtc_UWord8* rtcpbuffer,
pwestin@webrtc.org5e954812012-02-10 12:13:12 +0000171 WebRtc_UWord32& pos,
172 bool repeat);
niklase@google.com470e71d2011-07-07 08:21:25 +0000173 WebRtc_Word32 BuildSLI(WebRtc_UWord8* rtcpbuffer,
174 WebRtc_UWord32& pos,
175 const WebRtc_UWord8 pictureID);
176 WebRtc_Word32 BuildRPSI(WebRtc_UWord8* rtcpbuffer,
177 WebRtc_UWord32& pos,
178 const WebRtc_UWord64 pictureID,
179 const WebRtc_UWord8 payloadType);
180
181 WebRtc_Word32 BuildNACK(WebRtc_UWord8* rtcpbuffer,
182 WebRtc_UWord32& pos,
183 const WebRtc_Word32 nackSize,
184 const WebRtc_UWord16* nackList);
185
186private:
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000187 WebRtc_Word32 _id;
188 const bool _audio;
pwestin@webrtc.org0644b1d2011-12-01 15:42:31 +0000189 RtpRtcpClock& _clock;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000190 RTCPMethod _method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000192 ModuleRtpRtcpImpl& _rtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000194 CriticalSectionWrapper* _criticalSectionTransport;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000195 Transport* _cbTransport;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000197 CriticalSectionWrapper* _criticalSectionRTCPSender;
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 bool _usingNack;
199 bool _sending;
200 bool _sendTMMBN;
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000201 bool _REMB;
202 bool _sendREMB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000203 bool _TMMBR;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000204 bool _IJ;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
pwestin@webrtc.org18530052012-07-03 10:41:54 +0000206 WebRtc_Word64 _nextTimeToSendRTCP;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000208 uint32_t start_timestamp_;
209 uint32_t last_rtp_timestamp_;
210 int64_t last_frame_capture_time_ms_;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000211 WebRtc_UWord32 _SSRC;
212 WebRtc_UWord32 _remoteSSRC; // SSRC that we receive on our RTP channel
213 char _CNAME[RTCP_CNAME_SIZE];
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000215 std::map<WebRtc_UWord32, RTCPReportBlock*> _reportBlocks;
216 std::map<WebRtc_UWord32, RTCPUtility::RTCPCnameInformation*> _csrcCNAMEs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
218 WebRtc_Word32 _cameraDelayMS;
219
220 // Sent
221 WebRtc_UWord32 _lastSendReport[RTCP_NUMBER_OF_SR]; // allow packet loss and RTT above 1 sec
222 WebRtc_UWord32 _lastRTCPTime[RTCP_NUMBER_OF_SR];
223
224 // send CSRCs
225 WebRtc_UWord8 _CSRCs;
226 WebRtc_UWord32 _CSRC[kRtpCsrcSize];
227 bool _includeCSRCs;
228
229 // Full intra request
230 WebRtc_UWord8 _sequenceNumberFIR;
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000232 // REMB
233 WebRtc_UWord8 _lengthRembSSRC;
234 WebRtc_UWord8 _sizeRembSSRC;
235 WebRtc_UWord32* _rembSSRC;
236 WebRtc_UWord32 _rembBitrate;
237
niklase@google.com470e71d2011-07-07 08:21:25 +0000238 TMMBRHelp _tmmbrHelp;
239 WebRtc_UWord32 _tmmbr_Send;
240 WebRtc_UWord32 _packetOH_Send;
niklase@google.com470e71d2011-07-07 08:21:25 +0000241
242 // APP
243 bool _appSend;
244 WebRtc_UWord8 _appSubType;
245 WebRtc_UWord32 _appName;
246 WebRtc_UWord8* _appData;
247 WebRtc_UWord16 _appLength;
248
249 // XR VoIP metric
250 bool _xrSendVoIPMetric;
251 RTCPVoIPMetric _xrVoIPMetric;
252};
253} // namespace webrtc
254
255#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_SENDER_H_