Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / rtp_rtcp / source / rtcp_receiver.h
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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_RECEIVER_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
13
14 #include <map>
15 #include <vector>
16 #include <set>
17
18 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
22 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
23 #include "webrtc/typedefs.h"
24
25 namespace webrtc {
26 class ModuleRtpRtcpImpl;
27
28 class RTCPReceiver : public TMMBRHelp
29 {
30 public:
31     RTCPReceiver(const int32_t id, Clock* clock,
32                  ModuleRtpRtcpImpl* owner);
33     virtual ~RTCPReceiver();
34
35     void ChangeUniqueId(const int32_t id);
36
37     RTCPMethod Status() const;
38     int32_t SetRTCPStatus(const RTCPMethod method);
39
40     int64_t LastReceived();
41     int64_t LastReceivedReceiverReport() const;
42
43     void SetSsrcs(uint32_t main_ssrc,
44                   const std::set<uint32_t>& registered_ssrcs);
45     void SetRelaySSRC( const uint32_t ssrc);
46     int32_t SetRemoteSSRC( const uint32_t ssrc);
47     uint32_t RemoteSSRC() const;
48
49     uint32_t RelaySSRC() const;
50
51     void RegisterRtcpObservers(RtcpIntraFrameObserver* intra_frame_callback,
52                                RtcpBandwidthObserver* bandwidth_callback,
53                                RtcpFeedback* feedback_callback);
54
55     int32_t IncomingRTCPPacket(
56         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
57         RTCPUtility::RTCPParserV2 *rtcpParser);
58
59     void TriggerCallbacksFromRTCPPacket(RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
60
61     // get received cname
62     int32_t CNAME(const uint32_t remoteSSRC,
63                   char cName[RTCP_CNAME_SIZE]) const;
64
65     // get received NTP
66     bool NTP(uint32_t* ReceivedNTPsecs,
67              uint32_t* ReceivedNTPfrac,
68              uint32_t* RTCPArrivalTimeSecs,
69              uint32_t* RTCPArrivalTimeFrac,
70              uint32_t* rtcp_timestamp) const;
71
72    bool LastReceivedXrReferenceTimeInfo(RtcpReceiveTimeInfo* info) const;
73
74     // get rtt
75     int32_t RTT(uint32_t remoteSSRC,
76                 uint16_t* RTT,
77                 uint16_t* avgRTT,
78                 uint16_t* minRTT,
79                 uint16_t* maxRTT) const;
80
81     int32_t ResetRTT(const uint32_t remoteSSRC);
82
83     int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
84
85     bool GetAndResetXrRrRtt(uint16_t* rtt_ms);
86
87     // get statistics
88     int32_t StatisticsReceived(
89         std::vector<RTCPReportBlock>* receiveBlocks) const;
90
91     void GetPacketTypeCounter(RtcpPacketTypeCounter* packet_counter) const;
92
93     // Returns true if we haven't received an RTCP RR for several RTCP
94     // intervals, but only triggers true once.
95     bool RtcpRrTimeout(int64_t rtcp_interval_ms);
96
97     // Returns true if we haven't received an RTCP RR telling the receive side
98     // has not received RTP packets for too long, i.e. extended highest sequence
99     // number hasn't increased for several RTCP intervals. The function only
100     // returns true once until a new RR is received.
101     bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
102
103     // Get TMMBR
104     int32_t TMMBRReceived(const uint32_t size,
105                           const uint32_t accNumCandidates,
106                           TMMBRSet* candidateSet) const;
107
108     bool UpdateRTCPReceiveInformationTimers();
109
110     int32_t BoundingSet(bool &tmmbrOwner, TMMBRSet* boundingSetRec);
111
112     int32_t UpdateTMMBR();
113
114     void RegisterRtcpStatisticsCallback(RtcpStatisticsCallback* callback);
115     RtcpStatisticsCallback* GetRtcpStatisticsCallback();
116
117 protected:
118     RTCPHelp::RTCPReportBlockInformation* CreateReportBlockInformation(const uint32_t remoteSSRC);
119     RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(const uint32_t remoteSSRC) const;
120
121     RTCPUtility::RTCPCnameInformation* CreateCnameInformation(const uint32_t remoteSSRC);
122     RTCPUtility::RTCPCnameInformation* GetCnameInformation(const uint32_t remoteSSRC) const;
123
124     RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation(const uint32_t remoteSSRC);
125     RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(const uint32_t remoteSSRC);
126
127     void UpdateReceiveInformation( RTCPHelp::RTCPReceiveInformation& receiveInformation);
128
129     void HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser,
130                                     RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
131
132     void HandleReportBlock(const RTCPUtility::RTCPPacket& rtcpPacket,
133                            RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
134                            const uint32_t remoteSSRC,
135                            const uint8_t numberOfReportBlocks);
136
137     void HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser);
138
139     void HandleSDESChunk(RTCPUtility::RTCPParserV2& rtcpParser);
140
141     void HandleXrHeader(RTCPUtility::RTCPParserV2& parser,
142                         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
143
144     void HandleXrReceiveReferenceTime(
145         RTCPUtility::RTCPParserV2& parser,
146         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
147
148     void HandleXrDlrrReportBlock(
149         RTCPUtility::RTCPParserV2& parser,
150         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
151
152     void HandleXrDlrrReportBlockItem(
153         const RTCPUtility::RTCPPacket& packet,
154         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
155
156     void HandleXRVOIPMetric(RTCPUtility::RTCPParserV2& rtcpParser,
157                             RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
158
159     void HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
160                     RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
161
162     void HandleNACKItem(const RTCPUtility::RTCPPacket& rtcpPacket,
163                         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
164
165     void HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser);
166
167     void HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
168                    RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
169
170     void HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
171                    RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
172
173     void HandleSLIItem(const RTCPUtility::RTCPPacket& rtcpPacket,
174                        RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
175
176     void HandleRPSI(RTCPUtility::RTCPParserV2& rtcpParser,
177                     RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
178
179     void HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
180                        RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
181
182     void HandleREMBItem(RTCPUtility::RTCPParserV2& rtcpParser,
183                         RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
184
185     void HandleIJ(RTCPUtility::RTCPParserV2& rtcpParser,
186                   RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
187
188     void HandleIJItem(const RTCPUtility::RTCPPacket& rtcpPacket,
189                       RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
190
191     void HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
192                      RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
193
194     void HandleTMMBRItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
195                          const RTCPUtility::RTCPPacket& rtcpPacket,
196                          RTCPHelp::RTCPPacketInformation& rtcpPacketInformation,
197                          const uint32_t senderSSRC);
198
199     void HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
200                      RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
201
202     void HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
203                       RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
204
205     void HandleTMMBNItem(RTCPHelp::RTCPReceiveInformation& receiveInfo,
206                          const RTCPUtility::RTCPPacket& rtcpPacket);
207
208     void HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
209                    RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
210
211     void HandleFIRItem(RTCPHelp::RTCPReceiveInformation* receiveInfo,
212                        const RTCPUtility::RTCPPacket& rtcpPacket,
213                        RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
214
215     void HandleAPP(RTCPUtility::RTCPParserV2& rtcpParser,
216                    RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
217
218     void HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser,
219                        RTCPHelp::RTCPPacketInformation& rtcpPacketInformation);
220
221  private:
222   typedef std::map<uint32_t, RTCPHelp::RTCPReceiveInformation*>
223       ReceivedInfoMap;
224   int32_t           _id;
225   Clock*                  _clock;
226   RTCPMethod              _method;
227   int64_t           _lastReceived;
228   ModuleRtpRtcpImpl&      _rtpRtcp;
229
230   CriticalSectionWrapper* _criticalSectionFeedbacks;
231   RtcpFeedback*           _cbRtcpFeedback;
232   RtcpBandwidthObserver*  _cbRtcpBandwidthObserver;
233   RtcpIntraFrameObserver* _cbRtcpIntraFrameObserver;
234
235   CriticalSectionWrapper* _criticalSectionRTCPReceiver;
236   uint32_t          main_ssrc_;
237   uint32_t          _remoteSSRC;
238   std::set<uint32_t> registered_ssrcs_;
239
240   // Received send report
241   RTCPSenderInfo _remoteSenderInfo;
242   // when did we receive the last send report
243   uint32_t _lastReceivedSRNTPsecs;
244   uint32_t _lastReceivedSRNTPfrac;
245
246   // Received XR receive time report.
247   RtcpReceiveTimeInfo _remoteXRReceiveTimeInfo;
248   // Time when the report was received.
249   uint32_t _lastReceivedXRNTPsecs;
250   uint32_t _lastReceivedXRNTPfrac;
251   // Estimated rtt, zero when there is no valid estimate.
252   uint16_t xr_rr_rtt_ms_;
253
254   // Received report blocks.
255   std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>
256       _receivedReportBlockMap;
257   ReceivedInfoMap _receivedInfoMap;
258   std::map<uint32_t, RTCPUtility::RTCPCnameInformation*>
259       _receivedCnameMap;
260
261   uint32_t            _packetTimeOutMS;
262
263   // The last time we received an RTCP RR.
264   int64_t _lastReceivedRrMs;
265
266   // The time we last received an RTCP RR telling we have ssuccessfully
267   // delivered RTP packet to the remote side.
268   int64_t _lastIncreasedSequenceNumberMs;
269
270   RtcpStatisticsCallback* stats_callback_;
271
272   RtcpPacketTypeCounter packet_type_counter_;
273 };
274 }  // namespace webrtc
275 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_