live
RTCP.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2017 Live Networks, Inc. All rights reserved.
18 // RTCP
19 // C++ header
20 
21 #ifndef _RTCP_HH
22 #define _RTCP_HH
23 
24 #ifndef _RTP_SINK_HH
25 #include "RTPSink.hh"
26 #endif
27 #ifndef _RTP_SOURCE_HH
28 #include "RTPSource.hh"
29 #endif
30 
31 class SDESItem {
32 public:
33  SDESItem(unsigned char tag, unsigned char const* value);
34 
35  unsigned char const* data() const {return fData;}
36  unsigned totalSize() const;
37 
38 private:
39  unsigned char fData[2 + 0xFF]; // first 2 bytes are tag and length
40 };
41 
42 typedef void RTCPAppHandlerFunc(void* clientData,
43  u_int8_t subtype, u_int32_t nameBytes/*big-endian order*/,
44  u_int8_t* appDependentData, unsigned appDependentDataSize);
45 
46 class RTCPMemberDatabase; // forward
47 
48 class RTCPInstance: public Medium {
49 public:
51  unsigned totSessionBW, /* in kbps */
52  unsigned char const* cname,
53  RTPSink* sink,
54  RTPSource* source,
55  Boolean isSSMSource = False);
56 
57  static Boolean lookupByName(UsageEnvironment& env, char const* instanceName,
58  RTCPInstance*& resultInstance);
59 
60  unsigned numMembers() const;
61  unsigned totSessionBW() const { return fTotSessionBW; }
62 
63  void setByeHandler(TaskFunc* handlerTask, void* clientData,
64  Boolean handleActiveParticipantsOnly = True);
65  // Assigns a handler routine to be called if a "BYE" arrives.
66  // The handler is called once only; for subsequent "BYE"s,
67  // "setByeHandler()" would need to be called again.
68  // If "handleActiveParticipantsOnly" is True, then the handler is called
69  // only if the SSRC is for a known sender (if we have a "RTPSource"),
70  // or if the SSRC is for a known receiver (if we have a "RTPSink").
71  // This prevents (for example) the handler for a multicast receiver being
72  // called if some other multicast receiver happens to exit.
73  // If "handleActiveParticipantsOnly" is False, then the handler is called
74  // for any incoming RTCP "BYE".
75  // (To remove an existing "BYE" handler, call "setByeHandler()" again, with a "handlerTask" of NULL.)
76  void setSRHandler(TaskFunc* handlerTask, void* clientData);
77  void setRRHandler(TaskFunc* handlerTask, void* clientData);
78  // Assigns a handler routine to be called if a "SR" or "RR" packet
79  // (respectively) arrives. Unlike "setByeHandler()", the handler will
80  // be called once for each incoming "SR" or "RR". (To turn off handling,
81  // call the function again with "handlerTask" (and "clientData") as NULL.)
82  void setSpecificRRHandler(netAddressBits fromAddress, Port fromPort,
83  TaskFunc* handlerTask, void* clientData);
84  // Like "setRRHandler()", but applies only to "RR" packets that come from
85  // a specific source address and port. (Note that if both a specific
86  // and a general "RR" handler function is set, then both will be called.)
87  void unsetSpecificRRHandler(netAddressBits fromAddress, Port fromPort); // equivalent to setSpecificRRHandler(..., NULL, NULL);
88  void setAppHandler(RTCPAppHandlerFunc* handlerTask, void* clientData);
89  // Assigns a handler routine to be called whenever an "APP" packet arrives. (To turn off
90  // handling, call the function again with "handlerTask" (and "clientData") as NULL.)
91  void sendAppPacket(u_int8_t subtype, char const* name,
92  u_int8_t* appDependentData, unsigned appDependentDataSize);
93  // Sends a custom RTCP "APP" packet to the peer(s). The parameters correspond to their
94  // respective fields as described in the RTP/RTCP definition (RFC 3550).
95  // Note that only the low-order 5 bits of "subtype" are used, and only the first 4 bytes
96  // of "name" are used. (If "name" has fewer than 4 bytes, or is NULL,
97  // then the remaining bytes are '\0'.)
98 
99  Groupsock* RTCPgs() const { return fRTCPInterface.gs(); }
100 
101  void setStreamSocket(int sockNum, unsigned char streamChannelId);
102  void addStreamSocket(int sockNum, unsigned char streamChannelId);
103  void removeStreamSocket(int sockNum, unsigned char streamChannelId) {
104  fRTCPInterface.removeStreamSocket(sockNum, streamChannelId);
105  }
106  // hacks to allow sending RTP over TCP (RFC 2236, section 10.12)
107 
109  void* handlerClientData) {
111  handlerClientData);
112  }
113 
114  void injectReport(u_int8_t const* packet, unsigned packetSize, struct sockaddr_in const& fromAddress);
115  // Allows an outside party to inject an RTCP report (from other than the network interface)
116 
117 protected:
118  RTCPInstance(UsageEnvironment& env, Groupsock* RTPgs, unsigned totSessionBW,
119  unsigned char const* cname,
120  RTPSink* sink, RTPSource* source,
121  Boolean isSSMSource);
122  // called only by createNew()
123  virtual ~RTCPInstance();
124 
125  virtual void noteArrivingRR(struct sockaddr_in const& fromAddressAndPort,
126  int tcpSocketNum, unsigned char tcpStreamChannelId);
127 
128  void incomingReportHandler1();
129 
130 private:
131  // redefined virtual functions:
132  virtual Boolean isRTCPInstance() const;
133 
134 private:
135  Boolean addReport(Boolean alwaysAdd = False);
136  void addSR();
137  void addRR();
138  void enqueueCommonReportPrefix(unsigned char packetType, u_int32_t SSRC,
139  unsigned numExtraWords = 0);
141  void enqueueReportBlock(RTPReceptionStats* receptionStats);
142  void addSDES();
143  void addBYE();
144 
145  void sendBuiltPacket();
146 
147  static void onExpire(RTCPInstance* instance);
148  void onExpire1();
149 
150  static void incomingReportHandler(RTCPInstance* instance, int /*mask*/);
151  void processIncomingReport(unsigned packetSize, struct sockaddr_in const& fromAddressAndPort,
152  int tcpSocketNum, unsigned char tcpStreamChannelId);
153  void onReceive(int typeOfPacket, int totPacketSize, u_int32_t ssrc);
154 
155 private:
156  u_int8_t* fInBuf;
160  unsigned fTotSessionBW;
164 
166  RTCPMemberDatabase* fKnownMembers;
167  unsigned fOutgoingReportCount; // used for SSRC member aging
168 
169  double fAveRTCPSize;
174 
177  u_int32_t fLastReceivedSSRC;
182 
193 
194 public: // because this stuff is used by an external "C" function
195  void schedule(double nextTime);
196  void reschedule(double nextTime);
197  void sendReport();
198  void sendBYE();
199  int typeOfEvent() {return fTypeOfEvent;}
201  int packetType() {return fTypeOfPacket;}
203  int checkNewSSRC();
204  void removeLastReceivedSSRC();
205  void removeSSRC(u_int32_t ssrc, Boolean alsoRemoveStats);
206 };
207 
208 // RTCP packet types:
209 const unsigned char RTCP_PT_SR = 200;
210 const unsigned char RTCP_PT_RR = 201;
211 const unsigned char RTCP_PT_SDES = 202;
212 const unsigned char RTCP_PT_BYE = 203;
213 const unsigned char RTCP_PT_APP = 204;
214 const unsigned char RTCP_PT_RTPFB = 205; // Generic RTP Feedback [RFC4585]
215 const unsigned char RTCP_PT_PSFB = 206; // Payload-specific [RFC4585]
216 const unsigned char RTCP_PT_XR = 207; // extended report [RFC3611]
217 const unsigned char RTCP_PT_AVB = 208; // AVB RTCP packet ["Standard for Layer 3 Transport Protocol for Time Sensitive Applications in Local Area Networks." Work in progress.]
218 const unsigned char RTCP_PT_RSI = 209; // Receiver Summary Information [RFC5760]
219 const unsigned char RTCP_PT_TOKEN = 210; // Port Mapping [RFC6284]
220 const unsigned char RTCP_PT_IDMS = 211; // IDMS Settings [RFC7272]
221 
222 // SDES tags:
223 const unsigned char RTCP_SDES_END = 0;
224 const unsigned char RTCP_SDES_CNAME = 1;
225 const unsigned char RTCP_SDES_NAME = 2;
226 const unsigned char RTCP_SDES_EMAIL = 3;
227 const unsigned char RTCP_SDES_PHONE = 4;
228 const unsigned char RTCP_SDES_LOC = 5;
229 const unsigned char RTCP_SDES_TOOL = 6;
230 const unsigned char RTCP_SDES_NOTE = 7;
231 const unsigned char RTCP_SDES_PRIV = 8;
232 
233 #endif
virtual void noteArrivingRR(struct sockaddr_in const &fromAddressAndPort, int tcpSocketNum, unsigned char tcpStreamChannelId)
unsigned char Boolean
Definition: Boolean.hh:25
void setStreamSocket(int sockNum, unsigned char streamChannelId)
RTPSource * fSource
Definition: RTCP.hh:162
Boolean addReport(Boolean alwaysAdd=False)
const unsigned char RTCP_PT_IDMS
Definition: RTCP.hh:220
const unsigned char RTCP_PT_BYE
Definition: RTCP.hh:212
const unsigned char RTCP_PT_RTPFB
Definition: RTCP.hh:214
int fLastSentSize
Definition: RTCP.hh:175
void * fByeHandlerClientData
Definition: RTCP.hh:184
TaskFunc * fByeHandlerTask
Definition: RTCP.hh:183
u_int32_t netAddressBits
Definition: NetAddress.hh:39
const Boolean False
Definition: Boolean.hh:28
void removeStreamSocket(int sockNum, unsigned char streamChannelId)
Definition: RTCP.hh:103
TaskFunc * fRRHandlerTask
Definition: RTCP.hh:188
const unsigned char RTCP_PT_APP
Definition: RTCP.hh:213
const unsigned char RTCP_PT_RSI
Definition: RTCP.hh:218
void TaskFunc(void *clientData)
void sendReport()
void removeSSRC(u_int32_t ssrc, Boolean alsoRemoveStats)
int fLastReceivedSize
Definition: RTCP.hh:176
unsigned char const * data() const
Definition: RTCP.hh:35
void onExpire1()
u_int32_t fLastReceivedSSRC
Definition: RTCP.hh:177
int fTypeOfPacket
Definition: RTCP.hh:179
void setByeHandler(TaskFunc *handlerTask, void *clientData, Boolean handleActiveParticipantsOnly=True)
void setRRHandler(TaskFunc *handlerTask, void *clientData)
void schedule(double nextTime)
int receivedPacketSize()
Definition: RTCP.hh:202
virtual ~RTCPInstance()
void setAuxilliaryReadHandler(AuxHandlerFunc *handlerFunc, void *handlerClientData)
Definition: RTPInterface.hh:88
void AuxHandlerFunc(void *clientData, unsigned char *packet, unsigned &packetSize)
Definition: RTPInterface.hh:35
void removeStreamSocket(int sockNum, unsigned char streamChannelId)
unsigned fNumBytesAlreadyRead
Definition: RTCP.hh:157
AddressPortLookupTable * fSpecificRRHandlerTable
Definition: RTCP.hh:190
void removeLastReceivedSSRC()
const unsigned char RTCP_PT_PSFB
Definition: RTCP.hh:215
unsigned totalSize() const
RTPInterface fRTCPInterface
Definition: RTCP.hh:159
static void incomingReportHandler(RTCPInstance *instance, int)
unsigned numMembers() const
const unsigned char RTCP_SDES_CNAME
Definition: RTCP.hh:224
void addStreamSocket(int sockNum, unsigned char streamChannelId)
int fPrevNumMembers
Definition: RTCP.hh:173
unsigned totSessionBW() const
Definition: RTCP.hh:61
int fIsInitial
Definition: RTCP.hh:170
void setAuxilliaryReadHandler(AuxHandlerFunc *handlerFunc, void *handlerClientData)
Definition: RTCP.hh:108
void sendBYE()
const unsigned char RTCP_SDES_LOC
Definition: RTCP.hh:228
void onReceive(int typeOfPacket, int totPacketSize, u_int32_t ssrc)
SDESItem(unsigned char tag, unsigned char const *value)
virtual Boolean isRTCPInstance() const
const unsigned char RTCP_PT_SDES
Definition: RTCP.hh:211
u_int8_t * fInBuf
Definition: RTCP.hh:156
const unsigned char RTCP_PT_AVB
Definition: RTCP.hh:217
TaskFunc * fSRHandlerTask
Definition: RTCP.hh:186
const unsigned char RTCP_PT_TOKEN
Definition: RTCP.hh:219
double fAveRTCPSize
Definition: RTCP.hh:169
void addSDES()
RTCPInstance(UsageEnvironment &env, Groupsock *RTPgs, unsigned totSessionBW, unsigned char const *cname, RTPSink *sink, RTPSource *source, Boolean isSSMSource)
OutPacketBuffer * fOutBuf
Definition: RTCP.hh:158
unsigned char fData[2+0xFF]
Definition: RTCP.hh:39
void enqueueCommonReportPrefix(unsigned char packetType, u_int32_t SSRC, unsigned numExtraWords=0)
int checkNewSSRC()
unsigned fLastPacketSentSize
Definition: RTCP.hh:181
void setSRHandler(TaskFunc *handlerTask, void *clientData)
RTCPMemberDatabase * fKnownMembers
Definition: RTCP.hh:166
Definition: RTCP.hh:31
int fTypeOfEvent
Definition: RTCP.hh:178
Definition: Media.hh:50
void injectReport(u_int8_t const *packet, unsigned packetSize, struct sockaddr_in const &fromAddress)
const unsigned char RTCP_SDES_TOOL
Definition: RTCP.hh:229
static Boolean lookupByName(UsageEnvironment &env, char const *instanceName, RTCPInstance *&resultInstance)
void RTCPAppHandlerFunc(void *clientData, u_int8_t subtype, u_int32_t nameBytes, u_int8_t *appDependentData, unsigned appDependentDataSize)
Definition: RTCP.hh:42
void incomingReportHandler1()
void * fRRHandlerClientData
Definition: RTCP.hh:189
void sendBuiltPacket()
unsigned fTotSessionBW
Definition: RTCP.hh:160
const unsigned char RTCP_SDES_NAME
Definition: RTCP.hh:225
static RTCPInstance * createNew(UsageEnvironment &env, Groupsock *RTCPgs, unsigned totSessionBW, unsigned char const *cname, RTPSink *sink, RTPSource *source, Boolean isSSMSource=False)
unsigned fOutgoingReportCount
Definition: RTCP.hh:167
void enqueueReportBlock(RTPReceptionStats *receptionStats)
const unsigned char RTCP_PT_SR
Definition: RTCP.hh:209
SDESItem fCNAME
Definition: RTCP.hh:165
double fPrevReportTime
Definition: RTCP.hh:171
void * fAppHandlerClientData
Definition: RTCP.hh:192
double fNextReportTime
Definition: RTCP.hh:172
int sentPacketSize()
Definition: RTCP.hh:200
RTCPAppHandlerFunc * fAppHandlerTask
Definition: RTCP.hh:191
int packetType()
Definition: RTCP.hh:201
void processIncomingReport(unsigned packetSize, struct sockaddr_in const &fromAddressAndPort, int tcpSocketNum, unsigned char tcpStreamChannelId)
int typeOfEvent()
Definition: RTCP.hh:199
void * fSRHandlerClientData
Definition: RTCP.hh:187
Boolean fByeHandleActiveParticipantsOnly
Definition: RTCP.hh:185
void setSpecificRRHandler(netAddressBits fromAddress, Port fromPort, TaskFunc *handlerTask, void *clientData)
RTPSink * fSink
Definition: RTCP.hh:161
const unsigned char RTCP_SDES_END
Definition: RTCP.hh:223
const Boolean True
Definition: Boolean.hh:31
void unsetSpecificRRHandler(netAddressBits fromAddress, Port fromPort)
void sendAppPacket(u_int8_t subtype, char const *name, u_int8_t *appDependentData, unsigned appDependentDataSize)
void * packet
const unsigned char RTCP_PT_XR
Definition: RTCP.hh:216
const unsigned char RTCP_SDES_PHONE
Definition: RTCP.hh:227
void setAppHandler(RTCPAppHandlerFunc *handlerTask, void *clientData)
Groupsock * gs() const
Definition: RTPInterface.hh:60
void enqueueCommonReportSuffix()
void reschedule(double nextTime)
const unsigned char RTCP_PT_RR
Definition: RTCP.hh:210
static void onExpire(RTCPInstance *instance)
const unsigned char RTCP_SDES_EMAIL
Definition: RTCP.hh:226
Boolean fHaveJustSentPacket
Definition: RTCP.hh:180
char const * name() const
Definition: Media.hh:61
Groupsock * RTCPgs() const
Definition: RTCP.hh:99
Boolean fIsSSMSource
Definition: RTCP.hh:163
const unsigned char RTCP_SDES_PRIV
Definition: RTCP.hh:231
const unsigned char RTCP_SDES_NOTE
Definition: RTCP.hh:230