liveMedia/include/RTCP.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2014 Live Networks, Inc.  All rights reserved.
00018 // RTCP
00019 // C++ header
00020 
00021 #ifndef _RTCP_HH
00022 #define _RTCP_HH
00023 
00024 #ifndef _RTP_SINK_HH
00025 #include "RTPSink.hh"
00026 #endif
00027 #ifndef _RTP_SOURCE_HH
00028 #include "RTPSource.hh"
00029 #endif
00030 
00031 class SDESItem {
00032 public:
00033   SDESItem(unsigned char tag, unsigned char const* value);
00034 
00035   unsigned char const* data() const {return fData;}
00036   unsigned totalSize() const;
00037 
00038 private:
00039   unsigned char fData[2 + 0xFF]; // first 2 bytes are tag and length
00040 };
00041 
00042 class RTCPMemberDatabase; // forward
00043 
00044 class RTCPInstance: public Medium {
00045 public:
00046   static RTCPInstance* createNew(UsageEnvironment& env, Groupsock* RTCPgs,
00047                                  unsigned totSessionBW, /* in kbps */
00048                                  unsigned char const* cname,
00049                                  RTPSink* sink,
00050                                  RTPSource* source,
00051                                  Boolean isSSMSource = False);
00052 
00053   static Boolean lookupByName(UsageEnvironment& env, char const* instanceName,
00054                               RTCPInstance*& resultInstance);
00055 
00056   unsigned numMembers() const;
00057   unsigned totSessionBW() const { return fTotSessionBW; }
00058 
00059   void setByeHandler(TaskFunc* handlerTask, void* clientData,
00060                      Boolean handleActiveParticipantsOnly = True);
00061       // Assigns a handler routine to be called if a "BYE" arrives.
00062       // The handler is called once only; for subsequent "BYE"s,
00063       // "setByeHandler()" would need to be called again.
00064       // If "handleActiveParticipantsOnly" is True, then the handler is called
00065       // only if the SSRC is for a known sender (if we have a "RTPSource"),
00066       // or if the SSRC is for a known receiver (if we have a "RTPSink").
00067       // This prevents (for example) the handler for a multicast receiver being
00068       // called if some other multicast receiver happens to exit.
00069       // If "handleActiveParticipantsOnly" is False, then the handler is called
00070       // for any incoming RTCP "BYE".
00071       // (To remove an existing "BYE" handler, call "setByeHandler()" again, with a "handlerTask" of NULL.)
00072   void setSRHandler(TaskFunc* handlerTask, void* clientData);
00073   void setRRHandler(TaskFunc* handlerTask, void* clientData);
00074       // Assigns a handler routine to be called if a "SR" or "RR"
00075       // (respectively) arrives.  Unlike "setByeHandler()", the handler will
00076       // be called once for each incoming "SR" or "RR".  (To turn off handling,
00077       // call the function again with "handlerTask" (and "clientData") as NULL.
00078   void setSpecificRRHandler(netAddressBits fromAddress, Port fromPort,
00079                             TaskFunc* handlerTask, void* clientData);
00080       // Like "setRRHandler()", but applies only to "RR" packets that come from
00081       // a specific source address and port.  (Note that if both a specific
00082       // and a general "RR" handler function is set, then both will be called.)
00083   void unsetSpecificRRHandler(netAddressBits fromAddress, Port fromPort); // equivalent to setSpecificRRHandler(..., NULL, NULL);
00084 
00085   Groupsock* RTCPgs() const { return fRTCPInterface.gs(); }
00086 
00087   void setStreamSocket(int sockNum, unsigned char streamChannelId);
00088   void addStreamSocket(int sockNum, unsigned char streamChannelId);
00089   void removeStreamSocket(int sockNum, unsigned char streamChannelId) {
00090     fRTCPInterface.removeStreamSocket(sockNum, streamChannelId);
00091   }
00092     // hacks to allow sending RTP over TCP (RFC 2236, section 10.12)
00093 
00094   void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc,
00095                                 void* handlerClientData) {
00096     fRTCPInterface.setAuxilliaryReadHandler(handlerFunc,
00097                                             handlerClientData);
00098   }
00099 
00100   void injectReport(u_int8_t const* packet, unsigned packetSize, struct sockaddr_in const& fromAddress);
00101     // Allows an outside party to inject an RTCP report (from other than the network interface)
00102 
00103 protected:
00104   RTCPInstance(UsageEnvironment& env, Groupsock* RTPgs, unsigned totSessionBW,
00105                unsigned char const* cname,
00106                RTPSink* sink, RTPSource* source,
00107                Boolean isSSMSource);
00108       // called only by createNew()
00109   virtual ~RTCPInstance();
00110 
00111 private:
00112   // redefined virtual functions:
00113   virtual Boolean isRTCPInstance() const;
00114 
00115 private:
00116   Boolean addReport(Boolean alwaysAdd = False);
00117     void addSR();
00118     void addRR();
00119       void enqueueCommonReportPrefix(unsigned char packetType, u_int32_t SSRC,
00120                                      unsigned numExtraWords = 0);
00121       void enqueueCommonReportSuffix();
00122         void enqueueReportBlock(RTPReceptionStats* receptionStats);
00123   void addSDES();
00124   void addBYE();
00125 
00126   void sendBuiltPacket();
00127 
00128   static void onExpire(RTCPInstance* instance);
00129   void onExpire1();
00130 
00131   static void incomingReportHandler(RTCPInstance* instance, int /*mask*/);
00132   void incomingReportHandler1();
00133   void processIncomingReport(unsigned packetSize, struct sockaddr_in const& fromAddress,
00134                              int tcpSocketNum, unsigned char tcpStreamChannelId);
00135   void onReceive(int typeOfPacket, int totPacketSize, u_int32_t ssrc);
00136 
00137 private:
00138   u_int8_t* fInBuf;
00139   unsigned fNumBytesAlreadyRead;
00140   OutPacketBuffer* fOutBuf;
00141   RTPInterface fRTCPInterface;
00142   unsigned fTotSessionBW;
00143   RTPSink* fSink;
00144   RTPSource* fSource;
00145   Boolean fIsSSMSource;
00146 
00147   SDESItem fCNAME;
00148   RTCPMemberDatabase* fKnownMembers;
00149   unsigned fOutgoingReportCount; // used for SSRC member aging
00150 
00151   double fAveRTCPSize;
00152   int fIsInitial;
00153   double fPrevReportTime;
00154   double fNextReportTime;
00155   int fPrevNumMembers;
00156 
00157   int fLastSentSize;
00158   int fLastReceivedSize;
00159   u_int32_t fLastReceivedSSRC;
00160   int fTypeOfEvent;
00161   int fTypeOfPacket;
00162   Boolean fHaveJustSentPacket;
00163   unsigned fLastPacketSentSize;
00164 
00165   TaskFunc* fByeHandlerTask;
00166   void* fByeHandlerClientData;
00167   Boolean fByeHandleActiveParticipantsOnly;
00168   TaskFunc* fSRHandlerTask;
00169   void* fSRHandlerClientData;
00170   TaskFunc* fRRHandlerTask;
00171   void* fRRHandlerClientData;
00172   AddressPortLookupTable* fSpecificRRHandlerTable;
00173 
00174 public: // because this stuff is used by an external "C" function
00175   void schedule(double nextTime);
00176   void reschedule(double nextTime);
00177   void sendReport();
00178   void sendBYE();
00179   int typeOfEvent() {return fTypeOfEvent;}
00180   int sentPacketSize() {return fLastSentSize;}
00181   int packetType() {return fTypeOfPacket;}
00182   int receivedPacketSize() {return fLastReceivedSize;}
00183   int checkNewSSRC();
00184   void removeLastReceivedSSRC();
00185   void removeSSRC(u_int32_t ssrc, Boolean alsoRemoveStats);
00186 };
00187 
00188 // RTCP packet types:
00189 const unsigned char RTCP_PT_SR = 200;
00190 const unsigned char RTCP_PT_RR = 201;
00191 const unsigned char RTCP_PT_SDES = 202;
00192 const unsigned char RTCP_PT_BYE = 203;
00193 const unsigned char RTCP_PT_APP = 204;
00194 const unsigned char RTCP_PT_RTPFB = 205; // Generic RTP Feedback [RFC4585]
00195 const unsigned char RTCP_PT_PSFB = 206; // Payload-specific [RFC4585]
00196 const unsigned char RTCP_PT_XR = 207; // extended report [RFC3611]
00197 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.]
00198 const unsigned char RTCP_PT_RSI = 209; // Receiver Summary Information [RFC5760]
00199 const unsigned char RTCP_PT_TOKEN = 210; // Port Mapping [RFC6284]
00200 const unsigned char RTCP_PT_IDMS = 211; // IDMS Settings [RFC7272]
00201 
00202 // SDES tags:
00203 const unsigned char RTCP_SDES_END = 0;
00204 const unsigned char RTCP_SDES_CNAME = 1;
00205 const unsigned char RTCP_SDES_NAME = 2;
00206 const unsigned char RTCP_SDES_EMAIL = 3;
00207 const unsigned char RTCP_SDES_PHONE = 4;
00208 const unsigned char RTCP_SDES_LOC = 5;
00209 const unsigned char RTCP_SDES_TOOL = 6;
00210 const unsigned char RTCP_SDES_NOTE = 7;
00211 const unsigned char RTCP_SDES_PRIV = 8;
00212 
00213 #endif

Generated on Wed Nov 12 10:49:12 2014 for live by  doxygen 1.5.2