00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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];
00040 };
00041
00042 class RTCPMemberDatabase;
00043
00044 class RTCPInstance: public Medium {
00045 public:
00046 static RTCPInstance* createNew(UsageEnvironment& env, Groupsock* RTCPgs,
00047 unsigned totSessionBW,
00048 unsigned char const* cname,
00049 RTPSink* sink,
00050 RTPSource const* 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
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 void setSRHandler(TaskFunc* handlerTask, void* clientData);
00073 void setRRHandler(TaskFunc* handlerTask, void* clientData);
00074
00075
00076
00077
00078 void setSpecificRRHandler(netAddressBits fromAddress, Port fromPort,
00079 TaskFunc* handlerTask, void* clientData);
00080
00081
00082
00083 void unsetSpecificRRHandler(netAddressBits fromAddress, Port fromPort);
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
00093
00094 void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc,
00095 void* handlerClientData) {
00096 fRTCPInterface.setAuxilliaryReadHandler(handlerFunc,
00097 handlerClientData);
00098 }
00099
00100 protected:
00101 RTCPInstance(UsageEnvironment& env, Groupsock* RTPgs, unsigned totSessionBW,
00102 unsigned char const* cname,
00103 RTPSink* sink, RTPSource const* source,
00104 Boolean isSSMSource);
00105
00106 virtual ~RTCPInstance();
00107
00108 private:
00109
00110 virtual Boolean isRTCPInstance() const;
00111
00112 private:
00113 Boolean addReport(Boolean alwaysAdd = False);
00114 void addSR();
00115 void addRR();
00116 void enqueueCommonReportPrefix(unsigned char packetType, u_int32_t SSRC,
00117 unsigned numExtraWords = 0);
00118 void enqueueCommonReportSuffix();
00119 void enqueueReportBlock(RTPReceptionStats* receptionStats);
00120 void addSDES();
00121 void addBYE();
00122
00123 void sendBuiltPacket();
00124
00125 static void onExpire(RTCPInstance* instance);
00126 void onExpire1();
00127
00128 static void incomingReportHandler(RTCPInstance* instance, int );
00129 void incomingReportHandler1();
00130 void onReceive(int typeOfPacket, int totPacketSize, u_int32_t ssrc);
00131
00132 private:
00133 unsigned char* fInBuf;
00134 unsigned fNumBytesAlreadyRead;
00135 OutPacketBuffer* fOutBuf;
00136 RTPInterface fRTCPInterface;
00137 unsigned fTotSessionBW;
00138 RTPSink* fSink;
00139 RTPSource const* fSource;
00140 Boolean fIsSSMSource;
00141
00142 SDESItem fCNAME;
00143 RTCPMemberDatabase* fKnownMembers;
00144 unsigned fOutgoingReportCount;
00145
00146 double fAveRTCPSize;
00147 int fIsInitial;
00148 double fPrevReportTime;
00149 double fNextReportTime;
00150 int fPrevNumMembers;
00151
00152 int fLastSentSize;
00153 int fLastReceivedSize;
00154 u_int32_t fLastReceivedSSRC;
00155 int fTypeOfEvent;
00156 int fTypeOfPacket;
00157 Boolean fHaveJustSentPacket;
00158 unsigned fLastPacketSentSize;
00159
00160 TaskFunc* fByeHandlerTask;
00161 void* fByeHandlerClientData;
00162 Boolean fByeHandleActiveParticipantsOnly;
00163 TaskFunc* fSRHandlerTask;
00164 void* fSRHandlerClientData;
00165 TaskFunc* fRRHandlerTask;
00166 void* fRRHandlerClientData;
00167 AddressPortLookupTable* fSpecificRRHandlerTable;
00168
00169 public:
00170 void schedule(double nextTime);
00171 void reschedule(double nextTime);
00172 void sendReport();
00173 void sendBYE();
00174 int typeOfEvent() {return fTypeOfEvent;}
00175 int sentPacketSize() {return fLastSentSize;}
00176 int packetType() {return fTypeOfPacket;}
00177 int receivedPacketSize() {return fLastReceivedSize;}
00178 int checkNewSSRC();
00179 void removeLastReceivedSSRC();
00180 void removeSSRC(u_int32_t ssrc, Boolean alsoRemoveStats);
00181 };
00182
00183
00184 const unsigned char RTCP_PT_SR = 200;
00185 const unsigned char RTCP_PT_RR = 201;
00186 const unsigned char RTCP_PT_SDES = 202;
00187 const unsigned char RTCP_PT_BYE = 203;
00188 const unsigned char RTCP_PT_APP = 204;
00189
00190
00191 const unsigned char RTCP_SDES_END = 0;
00192 const unsigned char RTCP_SDES_CNAME = 1;
00193 const unsigned char RTCP_SDES_NAME = 2;
00194 const unsigned char RTCP_SDES_EMAIL = 3;
00195 const unsigned char RTCP_SDES_PHONE = 4;
00196 const unsigned char RTCP_SDES_LOC = 5;
00197 const unsigned char RTCP_SDES_TOOL = 6;
00198 const unsigned char RTCP_SDES_NOTE = 7;
00199 const unsigned char RTCP_SDES_PRIV = 8;
00200
00201 #endif