rtp.h

Go to the documentation of this file.
00001 /*
00002  * rtp.h
00003  *
00004  * RTP protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from
00025  * Vovida Networks, Inc. http://www.vovida.com.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: rtp.h,v $
00030  * Revision 2.21.2.2  2006/08/29 18:38:27  dsandras
00031  * Added function to better deal with reinvites.
00032  *
00033  * Revision 2.21.2.1  2006/02/06 04:38:37  csoutheren
00034  * Backported RTP payload mapping fixes from CVS head
00035  *
00036  * Revision 2.22  2006/02/02 07:02:57  csoutheren
00037  * Added RTP payload map to transcoders and connections to allow remote SIP endpoints
00038  * to change the payload type used for outgoing RTP.
00039  *
00040  * Revision 2.21  2005/12/30 14:29:15  dsandras
00041  * Removed the assumption that the jitter will contain a 8 kHz signal.
00042  *
00043  * Revision 2.20  2005/11/30 13:35:26  csoutheren
00044  * Changed tags for Doxygen
00045  *
00046  * Revision 2.19  2005/04/11 17:34:57  dsandras
00047  * Added support for dynamic sequence changes in case of Re-INVITE.
00048  *
00049  * Revision 2.18  2005/04/10 20:50:16  dsandras
00050  * Allow changes of remote transmit address and SyncSource in an established RTP connection.
00051  *
00052  * Revision 2.17  2004/10/02 11:50:54  rjongbloed
00053  * Fixed RTP media stream so assures RTP session is open before starting.
00054  *
00055  * Revision 2.16  2004/04/26 05:37:13  rjongbloed
00056  * Allowed for selectable auto deletion of RTP user data attached to an RTP session.
00057  *
00058  * Revision 2.15  2004/02/19 10:47:01  rjongbloed
00059  * Merged OpenH323 version 1.13.1 changes.
00060  *
00061  * Revision 2.14  2004/01/18 15:35:20  rjongbloed
00062  * More work on video support
00063  *
00064  * Revision 2.13  2003/01/07 04:39:53  robertj
00065  * Updated to OpenH323 v1.11.2
00066  *
00067  * Revision 2.12  2002/11/10 11:33:17  robertj
00068  * Updated to OpenH323 v1.10.3
00069  *
00070  * Revision 2.11  2002/09/16 02:52:35  robertj
00071  * Added #define so can select if #pragma interface/implementation is used on
00072  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00073  *
00074  * Revision 2.10  2002/09/04 06:01:47  robertj
00075  * Updated to OpenH323 v1.9.6
00076  *
00077  * Revision 2.9  2002/07/01 04:56:31  robertj
00078  * Updated to OpenH323 v1.9.1
00079  *
00080  * Revision 2.8  2002/04/10 03:10:13  robertj
00081  * Added referential (container) copy functions to session manager class.
00082  *
00083  * Revision 2.7  2002/02/13 02:30:06  robertj
00084  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00085  *
00086  * Revision 2.6  2002/02/11 09:32:12  robertj
00087  * Updated to openH323 v1.8.0
00088  *
00089  * Revision 2.5  2002/01/22 05:58:55  robertj
00090  * Put MaxPayloadType back in for backward compatibility
00091  *
00092  * Revision 2.4  2002/01/22 05:03:06  robertj
00093  * Added enum for illegal payload type value.
00094  *
00095  * Revision 2.3  2001/11/14 06:20:40  robertj
00096  * Changed sending of control channel reports to be timer based.
00097  *
00098  * Revision 2.2  2001/10/05 00:22:13  robertj
00099  * Updated to PWLib 1.2.0 and OpenH323 1.7.0
00100  *
00101  * Revision 2.1  2001/08/01 05:08:43  robertj
00102  * Moved default session ID's to OpalMediaFormat class.
00103  *
00104  * Revision 2.0  2001/07/27 15:48:24  robertj
00105  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00106  *
00107  * Revision 1.51  2003/10/27 06:03:39  csoutheren
00108  * Added support for QoS
00109  *   Thanks to Henry Harrison of AliceStreet
00110  *
00111  * Revision 1.50  2003/10/09 09:47:45  csoutheren
00112  * Fixed problem with re-opening RTP half-channels under unusual
00113  * circumstances. Thanks to Damien Sandras
00114  *
00115  * Revision 1.49  2003/05/14 13:46:39  rjongbloed
00116  * Removed hack of using special payload type for H.263 for a method which
00117  *   would be less prone to failure in the future.
00118  *
00119  * Revision 1.48  2003/05/02 04:57:43  robertj
00120  * Added header extension support to RTP data frame class.
00121  *
00122  * Revision 1.47  2003/05/02 04:21:53  craigs
00123  * Added hacked OpalH263 codec
00124  *
00125  * Revision 1.46  2003/02/07 00:30:41  robertj
00126  * Changes for bizarre usage of RTP code outside of scope of H.323 specs.
00127  *
00128  * Revision 1.45  2003/02/05 06:32:08  robertj
00129  * Fixed non-stun symmetric NAT support recently broken.
00130  *
00131  * Revision 1.44  2003/02/04 07:06:41  robertj
00132  * Added STUN support.
00133  *
00134  * Revision 1.43  2002/11/19 01:48:15  robertj
00135  * Allowed get/set of canonical anme and tool name.
00136  *
00137  * Revision 1.42  2002/11/12 22:10:48  robertj
00138  * Updated documentation.
00139  *
00140  * Revision 1.41  2002/10/31 00:33:29  robertj
00141  * Enhanced jitter buffer system so operates dynamically between minimum and
00142  *   maximum values. Altered API to assure app writers note the change!
00143  *
00144  * Revision 1.40  2002/09/26 04:01:58  robertj
00145  * Fixed calculation of fraction of packets lost in RR, thanks Awais Ali
00146  *
00147  * Revision 1.39  2002/09/16 01:14:15  robertj
00148  * Added #define so can select if #pragma interface/implementation is used on
00149  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00150  *
00151  * Revision 1.38  2002/09/03 05:47:02  robertj
00152  * Normalised the multi-include header prevention ifdef/define symbol.
00153  * Added copy constructor/operator for session manager.
00154  *
00155  * Revision 1.37  2002/08/05 10:03:47  robertj
00156  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00157  *
00158  * Revision 1.36  2002/05/28 02:37:37  robertj
00159  * Fixed reading data out of RTCP compound statements.
00160  *
00161  * Revision 1.35  2002/05/02 05:58:24  robertj
00162  * Changed the mechanism for sending RTCP reports so that they will continue
00163  *   to be sent regardless of if there is any actual data traffic.
00164  * Added support for compound RTCP statements for sender and receiver reports.
00165  *
00166  * Revision 1.34  2002/02/09 02:33:37  robertj
00167  * Improved payload type docuemntation and added Cisco CN.
00168  *
00169  * Revision 1.33  2002/01/22 07:08:26  robertj
00170  * Added IllegalPayloadType enum as need marker for none set
00171  *   and MaxPayloadType is a legal value.
00172  *
00173  * Revision 1.32  2001/11/09 05:39:54  craigs
00174  * Added initial T.38 support thanks to Adam Lazur
00175  *
00176  * Revision 1.31  2001/09/11 00:21:21  robertj
00177  * Fixed missing stack sizes in endpoint for cleaner thread and jitter thread.
00178  *
00179  * Revision 1.30  2001/07/06 06:32:22  robertj
00180  * Added flag and checks for RTP data having specific SSRC.
00181  * Changed transmitter IP address check so is based on first received
00182  *    PDU instead of expecting it to come from the host we are sending to.
00183  *
00184  * Revision 1.29  2001/06/04 11:37:48  robertj
00185  * Added thread safe enumeration functions of RTP sessions.
00186  * Added member access functions to UDP based RTP sessions.
00187  *
00188  * Revision 1.28  2001/04/24 06:15:50  robertj
00189  * Added work around for strange Cisco bug which suddenly starts sending
00190  *   RTP packets beginning at a difference sequence number base.
00191  *
00192  * Revision 1.27  2001/04/02 23:58:23  robertj
00193  * Added jitter calculation to RTP session.
00194  * Added trace of statistics.
00195  *
00196  * Revision 1.26  2001/02/09 05:16:24  robertj
00197  * Added #pragma interface for GNU C++.
00198  *
00199  * Revision 1.25  2000/12/18 08:58:30  craigs
00200  * Added ability set ports
00201  *
00202  * Revision 1.24  2000/09/25 01:44:31  robertj
00203  * Fixed possible race condition on shutdown of RTP session with jitter buffer.
00204  *
00205  * Revision 1.23  2000/09/21 02:06:06  craigs
00206  * Added handling for endpoints that return conformant, but useless, RTP address
00207  * and port numbers
00208  *
00209  * Revision 1.22  2000/05/23 12:57:28  robertj
00210  * Added ability to change IP Type Of Service code from applications.
00211  *
00212  * Revision 1.21  2000/05/18 11:53:34  robertj
00213  * Changes to support doc++ documentation generation.
00214  *
00215  * Revision 1.20  2000/05/04 11:49:21  robertj
00216  * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code.
00217  *
00218  * Revision 1.19  2000/05/02 04:32:25  robertj
00219  * Fixed copyright notice comment.
00220  *
00221  * Revision 1.18  2000/05/01 01:01:24  robertj
00222  * Added flag for what to do with out of orer packets (use if jitter, don't if not).
00223  *
00224  * Revision 1.17  2000/04/30 03:55:18  robertj
00225  * Improved the RTCP messages, epecially reports
00226  *
00227  * Revision 1.16  2000/04/10 17:39:21  robertj
00228  * Fixed debug output of RTP payload types to allow for unknown numbers.
00229  *
00230  * Revision 1.15  2000/04/05 03:17:31  robertj
00231  * Added more RTP statistics gathering and H.245 round trip delay calculation.
00232  *
00233  * Revision 1.14  2000/03/23 02:55:18  robertj
00234  * Added sending of SDES control packets.
00235  *
00236  * Revision 1.13  2000/03/20 20:54:04  robertj
00237  * Fixed problem with being able to reopen for reading an RTP_Session (Cisco compatibilty)
00238  *
00239  * Revision 1.12  2000/02/29 13:00:13  robertj
00240  * Added extra statistic display for RTP packets out of order.
00241  *
00242  * Revision 1.11  1999/12/30 09:14:31  robertj
00243  * Changed payload type functions to use enum.
00244  *
00245  * Revision 1.10  1999/12/23 23:02:35  robertj
00246  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00247  *
00248  * Revision 1.9  1999/11/20 05:35:57  robertj
00249  * Fixed possibly I/O block in RTP read loops.
00250  *
00251  * Revision 1.8  1999/11/19 09:17:15  robertj
00252  * Fixed problems with aycnhronous shut down of logical channels.
00253  *
00254  * Revision 1.7  1999/11/14 11:41:18  robertj
00255  * Added access functions to RTP statistics.
00256  *
00257  * Revision 1.6  1999/09/08 04:05:48  robertj
00258  * Added support for video capabilities & codec, still needs the actual codec itself!
00259  *
00260  * Revision 1.5  1999/08/31 12:34:18  robertj
00261  * Added gatekeeper support.
00262  *
00263  * Revision 1.4  1999/07/13 09:53:24  robertj
00264  * Fixed some problems with jitter buffer and added more debugging.
00265  *
00266  * Revision 1.3  1999/07/09 06:09:49  robertj
00267  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00268  *
00269  * Revision 1.2  1999/06/22 13:49:40  robertj
00270  * Added GSM support and further RTP protocol enhancements.
00271  *
00272  * Revision 1.1  1999/06/14 06:12:25  robertj
00273  * Changes for using RTP sessions correctly in H323 Logical Channel context
00274  *
00275  */
00276 
00277 #ifndef __OPAL_RTP_H
00278 #define __OPAL_RTP_H
00279 
00280 #ifdef P_USE_PRAGMA
00281 #pragma interface
00282 #endif
00283 
00284 
00285 #include <ptlib/sockets.h>
00286 
00287 
00288 class RTP_JitterBuffer;
00289 class PSTUNClient;
00290 
00291 
00292 
00294 // 
00295 // class to hold the QoS definitions for an RTP channel
00296 
00297 class RTP_QOS : public PObject
00298 {
00299   PCLASSINFO(RTP_QOS,PObject);
00300   public:
00301     PQoS dataQoS;
00302     PQoS ctrlQoS;
00303 };
00304 
00306 // Real Time Protocol - IETF RFC1889 and RFC1890
00307 
00310 class RTP_DataFrame : public PBYTEArray
00311 {
00312   PCLASSINFO(RTP_DataFrame, PBYTEArray);
00313 
00314   public:
00315     RTP_DataFrame(PINDEX payloadSize = 2048);
00316 
00317     enum {
00318       ProtocolVersion = 2,
00319       MinHeaderSize = 12,
00320       // Max Ethernet packet (1518 bytes) minus 802.3/CRC, 802.3, IP, UDP an RTP headers
00321       MaxEthernetPayloadSize = (1518-14-4-8-20-16-12)
00322     };
00323 
00324     enum PayloadTypes {
00325       PCMU,         // G.711 u-Law
00326       FS1016,       // Federal Standard 1016 CELP
00327       G721,         // ADPCM - Subsumed by G.726
00328       G726 = G721,
00329       GSM,          // GSM 06.10
00330       G7231,        // G.723.1 at 6.3kbps or 5.3 kbps
00331       DVI4_8k,      // DVI4 at 8kHz sample rate
00332       DVI4_16k,     // DVI4 at 16kHz sample rate
00333       LPC,          // LPC-10 Linear Predictive CELP
00334       PCMA,         // G.711 A-Law
00335       G722,         // G.722
00336       L16_Stereo,   // 16 bit linear PCM
00337       L16_Mono,     // 16 bit linear PCM
00338       G723,         // G.723
00339       CN,           // Confort Noise
00340       MPA,          // MPEG1 or MPEG2 audio
00341       G728,         // G.728 16kbps CELP
00342       DVI4_11k,     // DVI4 at 11kHz sample rate
00343       DVI4_22k,     // DVI4 at 22kHz sample rate
00344       G729,         // G.729 8kbps
00345       Cisco_CN,     // Cisco systems comfort noise (unofficial)
00346 
00347       CelB = 25,    // Sun Systems Cell-B video
00348       JPEG,         // Motion JPEG
00349       H261 = 31,    // H.261
00350       MPV,          // MPEG1 or MPEG2 video
00351       MP2T,         // MPEG2 transport system
00352       H263,         // H.263
00353 
00354       LastKnownPayloadType,
00355 
00356       DynamicBase = 96,
00357       MaxPayloadType = 127,
00358       IllegalPayloadType
00359     };
00360 
00361     typedef std::map<PayloadTypes, PayloadTypes> PayloadMapType;
00362 
00363     unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00364 
00365     BOOL GetExtension() const   { return (theArray[0]&0x10) != 0; }
00366     void SetExtension(BOOL ext);
00367 
00368     BOOL GetMarker() const { return (theArray[1]&0x80) != 0; }
00369     void SetMarker(BOOL m);
00370 
00371     PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00372     void         SetPayloadType(PayloadTypes t);
00373 
00374     WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00375     void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00376 
00377     DWORD GetTimestamp() const  { return *(PUInt32b *)&theArray[4]; }
00378     void  SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00379 
00380     DWORD GetSyncSource() const  { return *(PUInt32b *)&theArray[8]; }
00381     void  SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00382 
00383     PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00384     DWORD  GetContribSource(PINDEX idx) const;
00385     void   SetContribSource(PINDEX idx, DWORD src);
00386 
00387     PINDEX GetHeaderSize() const;
00388 
00389     int GetExtensionType() const; // -1 is no extension
00390     void   SetExtensionType(int type);
00391     PINDEX GetExtensionSize() const;
00392     BOOL   SetExtensionSize(PINDEX sz);
00393     BYTE * GetExtensionPtr() const;
00394 
00395     PINDEX GetPayloadSize() const { return payloadSize; }
00396     BOOL   SetPayloadSize(PINDEX sz);
00397     BYTE * GetPayloadPtr()     const { return (BYTE *)(theArray+GetHeaderSize()); }
00398 
00399   protected:
00400     PINDEX payloadSize;
00401 
00402 #if PTRACING
00403     friend ostream & operator<<(ostream & o, PayloadTypes t);
00404 #endif
00405 };
00406 
00407 PLIST(RTP_DataFrameList, RTP_DataFrame);
00408 
00409 
00412 class RTP_ControlFrame : public PBYTEArray
00413 {
00414   PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00415 
00416   public:
00417     RTP_ControlFrame(PINDEX compoundSize = 2048);
00418 
00419     unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00420 
00421     unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00422     void     SetCount(unsigned count);
00423 
00424     enum PayloadTypes {
00425       e_SenderReport = 200,
00426       e_ReceiverReport,
00427       e_SourceDescription,
00428       e_Goodbye,
00429       e_ApplDefined
00430     };
00431 
00432     unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00433     void     SetPayloadType(unsigned t);
00434 
00435     PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00436     void   SetPayloadSize(PINDEX sz);
00437 
00438     BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+compoundOffset+4); }
00439 
00440     BOOL ReadNextCompound();
00441     BOOL WriteNextCompound();
00442 
00443     PINDEX GetCompoundSize() const { return compoundSize; }
00444 
00445 #pragma pack(1)
00446     struct ReceiverReport {
00447       PUInt32b ssrc;      /* data source being reported */
00448       BYTE fraction;      /* fraction lost since last SR/RR */
00449       BYTE lost[3];       /* cumulative number of packets lost (signed!) */
00450       PUInt32b last_seq;  /* extended last sequence number received */
00451       PUInt32b jitter;    /* interarrival jitter */
00452       PUInt32b lsr;       /* last SR packet from this source */
00453       PUInt32b dlsr;      /* delay since last SR packet */
00454 
00455       unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00456       void SetLostPackets(unsigned lost);
00457     };
00458 
00459     struct SenderReport {
00460       PUInt32b ssrc;      /* source this RTCP packet refers to */
00461       PUInt32b ntp_sec;   /* NTP timestamp */
00462       PUInt32b ntp_frac;
00463       PUInt32b rtp_ts;    /* RTP timestamp */
00464       PUInt32b psent;     /* packets sent */
00465       PUInt32b osent;     /* octets sent */ 
00466     };
00467 
00468     enum DescriptionTypes {
00469       e_END,
00470       e_CNAME,
00471       e_NAME,
00472       e_EMAIL,
00473       e_PHONE,
00474       e_LOC,
00475       e_TOOL,
00476       e_NOTE,
00477       e_PRIV,
00478       NumDescriptionTypes
00479     };
00480 
00481     struct SourceDescription {
00482       PUInt32b src;       /* first SSRC/CSRC */
00483       struct Item {
00484         BYTE type;        /* type of SDES item (enum DescriptionTypes) */
00485         BYTE length;      /* length of SDES item (in octets) */
00486         char data[1];     /* text, not zero-terminated */
00487 
00488         const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00489         Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00490       } item[1];          /* list of SDES items */
00491     };
00492 
00493     SourceDescription & AddSourceDescription(
00494       DWORD src   
00495     );
00496 
00497     SourceDescription::Item & AddSourceDescriptionItem(
00498       SourceDescription & sdes, 
00499       unsigned type,            
00500       const PString & data      
00501     );
00502 #pragma pack()
00503 
00504   protected:
00505     PINDEX compoundOffset;
00506     PINDEX compoundSize;
00507 };
00508 
00509 
00510 class RTP_Session;
00511 
00516 class RTP_UserData : public PObject
00517 {
00518   PCLASSINFO(RTP_UserData, PObject);
00519 
00520   public:
00527     virtual void OnTxStatistics(
00528       const RTP_Session & session   
00529     ) const;
00530 
00537     virtual void OnRxStatistics(
00538       const RTP_Session & session   
00539     ) const;
00540 };
00541 
00542 
00545 class RTP_Session : public PObject
00546 {
00547   PCLASSINFO(RTP_Session, PObject);
00548 
00549   public:
00554     RTP_Session(
00555       unsigned id,                    
00556       RTP_UserData * userData = NULL, 
00557       BOOL autoDeleteUserData = TRUE  
00558     );
00559 
00563     ~RTP_Session();
00565 
00577     void SetJitterBufferSize(
00578       unsigned minJitterDelay, 
00579       unsigned maxJitterDelay, 
00580       unsigned timeUnits = 8,  
00581       PINDEX stackSize = 30000 
00582     );
00583 
00589     unsigned GetJitterBufferSize() const;
00590     
00593     unsigned GetJitterTimeUnits() const;
00594 
00596     virtual BOOL ModifyQOS(RTP_QOS * )
00597     { return FALSE; }
00598 
00604     BOOL ReadBufferedData(
00605       DWORD timestamp,        
00606       RTP_DataFrame & frame   
00607     );
00608 
00614     virtual BOOL ReadData(
00615       RTP_DataFrame & frame   
00616     ) = 0;
00617 
00620     virtual BOOL WriteData(
00621       RTP_DataFrame & frame   
00622     ) = 0;
00623 
00626     virtual BOOL WriteControl(
00627       RTP_ControlFrame & frame    
00628     ) = 0;
00629 
00632     virtual BOOL SendReport();
00633 
00636     virtual void Close(
00637       BOOL reading    
00638     ) = 0;
00639 
00642     virtual void Reopen(
00643       BOOL isReading
00644     ) = 0;
00645 
00648     virtual PString GetLocalHostName() = 0;
00650 
00653     enum SendReceiveStatus {
00654       e_ProcessPacket,
00655       e_IgnorePacket,
00656       e_AbortTransport
00657     };
00658     virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00659     virtual SendReceiveStatus OnReceiveData(const RTP_DataFrame & frame);
00660     virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00661 
00662     class ReceiverReport : public PObject  {
00663         PCLASSINFO(ReceiverReport, PObject);
00664       public:
00665         void PrintOn(ostream &) const;
00666 
00667         DWORD sourceIdentifier;
00668         DWORD fractionLost;         /* fraction lost since last SR/RR */
00669         DWORD totalLost;            /* cumulative number of packets lost (signed!) */
00670         DWORD lastSequenceNumber;   /* extended last sequence number received */
00671         DWORD jitter;               /* interarrival jitter */
00672         PTimeInterval lastTimestamp;/* last SR packet from this source */
00673         PTimeInterval delay;        /* delay since last SR packet */
00674     };
00675     PARRAY(ReceiverReportArray, ReceiverReport);
00676 
00677     class SenderReport : public PObject  {
00678         PCLASSINFO(SenderReport, PObject);
00679       public:
00680         void PrintOn(ostream &) const;
00681 
00682         DWORD sourceIdentifier;
00683         PTime realTimestamp;
00684         DWORD rtpTimestamp;
00685         DWORD packetsSent;
00686         DWORD octetsSent;
00687     };
00688     virtual void OnRxSenderReport(const SenderReport & sender,
00689                                   const ReceiverReportArray & reports);
00690     virtual void OnRxReceiverReport(DWORD src,
00691                                     const ReceiverReportArray & reports);
00692 
00693     class SourceDescription : public PObject  {
00694         PCLASSINFO(SourceDescription, PObject);
00695       public:
00696         SourceDescription(DWORD src) { sourceIdentifier = src; }
00697         void PrintOn(ostream &) const;
00698 
00699         DWORD            sourceIdentifier;
00700         POrdinalToString items;
00701     };
00702     PARRAY(SourceDescriptionArray, SourceDescription);
00703     virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00704 
00705     virtual void OnRxGoodbye(const PDWORDArray & sources,
00706                              const PString & reason);
00707 
00708     virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00709                                  const BYTE * data, PINDEX size);
00711 
00716     unsigned GetSessionID() const { return sessionID; }
00717 
00720     PString GetCanonicalName() const;
00721 
00724     void SetCanonicalName(const PString & name);
00725 
00728     PString GetToolName() const;
00729 
00732     void SetToolName(const PString & name);
00733 
00736     RTP_UserData * GetUserData() const { return userData; }
00737 
00740     void SetUserData(
00741       RTP_UserData * data,            
00742       BOOL autoDeleteUserData = TRUE  
00743     );
00744 
00747     DWORD GetSyncSourceOut() const { return syncSourceOut; }
00748 
00751     void IncrementReference() { referenceCount++; }
00752 
00755     BOOL DecrementReference() { return --referenceCount == 0; }
00756 
00759     BOOL WillIgnoreOtherSources() const { return ignoreOtherSources; }
00760 
00763     void SetIgnoreOtherSources(
00764       BOOL ignore   
00765     ) { ignoreOtherSources = ignore; }
00766 
00769     BOOL WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00770 
00773     void SetIgnoreOutOfOrderPackets(
00774       BOOL ignore   
00775     ) { ignoreOutOfOrderPackets = ignore; }
00776 
00779     void SetIgnorePayloadTypeChanges(
00780       BOOL ignore   
00781     ) { ignorePayloadTypeChanges = ignore; }
00782 
00785     const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00786 
00789     void SetReportTimeInterval(
00790       const PTimeInterval & interval 
00791     )  { reportTimeInterval = interval; }
00792 
00795     unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00796 
00799     void SetTxStatisticsInterval(
00800       unsigned packets   
00801     );
00802 
00805     unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00806 
00809     void SetRxStatisticsInterval(
00810       unsigned packets   
00811     );
00812 
00815     DWORD GetPacketsSent() const { return packetsSent; }
00816 
00819     DWORD GetOctetsSent() const { return octetsSent; }
00820 
00823     DWORD GetPacketsReceived() const { return packetsReceived; }
00824 
00827     DWORD GetOctetsReceived() const { return octetsReceived; }
00828 
00831     DWORD GetPacketsLost() const { return packetsLost; }
00832 
00835     DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00836 
00839     DWORD GetPacketsTooLate() const;
00840 
00845     DWORD GetAverageSendTime() const { return averageSendTime; }
00846 
00851     DWORD GetMaximumSendTime() const { return maximumSendTime; }
00852 
00857     DWORD GetMinimumSendTime() const { return minimumSendTime; }
00858 
00863     DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00864 
00869     DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00870 
00875     DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00876 
00881     DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00882 
00886     DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00888 
00889   protected:
00890     void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00891 
00892     unsigned           sessionID;
00893     PString            canonicalName;
00894     PString            toolName;
00895     unsigned           referenceCount;
00896     RTP_UserData     * userData;
00897     BOOL               autoDeleteUserData;
00898     RTP_JitterBuffer * jitter;
00899 
00900     BOOL          ignoreOtherSources;
00901     BOOL          ignoreOutOfOrderPackets;
00902     DWORD         syncSourceOut;
00903     DWORD         syncSourceIn;
00904     BOOL          allowSyncSourceInChange;
00905     BOOL          allowRemoteTransmitAddressChange;
00906     BOOL          allowSequenceChange;
00907     PTimeInterval reportTimeInterval;
00908     unsigned      txStatisticsInterval;
00909     unsigned      rxStatisticsInterval;
00910     WORD          lastSentSequenceNumber;
00911     WORD          expectedSequenceNumber;
00912     DWORD         lastSentTimestamp;
00913     PTimeInterval lastSentPacketTime;
00914     PTimeInterval lastReceivedPacketTime;
00915     WORD          lastRRSequenceNumber;
00916     PINDEX        consecutiveOutOfOrderPackets;
00917 
00918     // Statistics
00919     DWORD packetsSent;
00920     DWORD octetsSent;
00921     DWORD packetsReceived;
00922     DWORD octetsReceived;
00923     DWORD packetsLost;
00924     DWORD packetsOutOfOrder;
00925     DWORD averageSendTime;
00926     DWORD maximumSendTime;
00927     DWORD minimumSendTime;
00928     DWORD averageReceiveTime;
00929     DWORD maximumReceiveTime;
00930     DWORD minimumReceiveTime;
00931     DWORD jitterLevel;
00932     DWORD maximumJitterLevel;
00933 
00934     unsigned txStatisticsCount;
00935     unsigned rxStatisticsCount;
00936 
00937     DWORD    averageSendTimeAccum;
00938     DWORD    maximumSendTimeAccum;
00939     DWORD    minimumSendTimeAccum;
00940     DWORD    averageReceiveTimeAccum;
00941     DWORD    maximumReceiveTimeAccum;
00942     DWORD    minimumReceiveTimeAccum;
00943     DWORD    packetsLostSinceLastRR;
00944     DWORD    lastTransitTime;
00945     
00946     RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00947     BOOL ignorePayloadTypeChanges;
00948 
00949     PMutex reportMutex;
00950     PTimer reportTimer;
00951 };
00952 
00953 
00956 class RTP_SessionManager : public PObject
00957 {
00958   PCLASSINFO(RTP_SessionManager, PObject);
00959 
00960   public:
00965     RTP_SessionManager();
00966     RTP_SessionManager(const RTP_SessionManager & sm);
00967     RTP_SessionManager & operator=(const RTP_SessionManager & sm);
00969 
00970 
00984     RTP_Session * UseSession(
00985       unsigned sessionID    
00986     );
00987 
00994     void AddSession(
00995       RTP_Session * session    
00996     );
00997 
01001     void ReleaseSession(
01002       unsigned sessionID    
01003     );
01004 
01009     RTP_Session * GetSession(
01010       unsigned sessionID    
01011     ) const;
01012 
01029     RTP_Session * First();
01030 
01037     RTP_Session * Next();
01038 
01046     void Exit();
01048 
01049 
01050   protected:
01051     PDICTIONARY(SessionDict, POrdinalKey, RTP_Session);
01052     SessionDict sessions;
01053     PMutex      mutex;
01054     PINDEX      enumerationIndex;
01055 };
01056 
01057 
01058 
01061 class RTP_UDP : public RTP_Session
01062 {
01063   PCLASSINFO(RTP_UDP, RTP_Session);
01064 
01065   public:
01070     RTP_UDP(
01071       unsigned id  
01072     );
01073 
01075     ~RTP_UDP();
01077 
01085     virtual BOOL ReadData(RTP_DataFrame & frame);
01086 
01089     virtual BOOL WriteData(RTP_DataFrame & frame);
01090 
01093     virtual BOOL WriteControl(RTP_ControlFrame & frame);
01094 
01097     virtual void Close(
01098       BOOL reading    
01099     );
01100 
01103     virtual PString GetLocalHostName();
01105 
01108     virtual BOOL ModifyQOS(RTP_QOS * rtpqos);
01109 
01114     BOOL Open(
01115       PIPSocket::Address localAddress,  
01116       WORD portBase,                    
01117       WORD portMax,                     
01118       BYTE ipTypeOfService,             
01119       PSTUNClient * stun = NULL,        
01120       RTP_QOS * rtpqos = NULL           
01121     );
01123 
01126     virtual void Reopen(BOOL isReading);
01128 
01133     PIPSocket::Address GetLocalAddress() const { return localAddress; }
01134 
01137     void SetLocalAddress(
01138       const PIPSocket::Address & addr
01139     ) { localAddress = addr; }
01140 
01143     PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01144 
01147     WORD GetLocalDataPort() const { return localDataPort; }
01148 
01151     WORD GetLocalControlPort() const { return localControlPort; }
01152 
01155     WORD GetRemoteDataPort() const { return remoteDataPort; }
01156 
01159     WORD GetRemoteControlPort() const { return remoteControlPort; }
01160 
01163     PUDPSocket & GetDataSocket() { return *dataSocket; }
01164 
01167     PUDPSocket & GetControlSocket() { return *controlSocket; }
01168 
01171     BOOL SetRemoteSocketInfo(
01172       PIPSocket::Address address,   
01173       WORD port,                    
01174       BOOL isDataPort               
01175     );
01176 
01179     void ApplyQOS(
01180       const PIPSocket::Address & addr
01181     );
01183 
01184   protected:
01185     SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01186     SendReceiveStatus ReadControlPDU();
01187     SendReceiveStatus ReadDataOrControlPDU(
01188       PUDPSocket & socket,
01189       PBYTEArray & frame,
01190       BOOL fromDataChannel
01191     );
01192 
01193     PIPSocket::Address localAddress;
01194     WORD               localDataPort;
01195     WORD               localControlPort;
01196 
01197     PIPSocket::Address remoteAddress;
01198     WORD               remoteDataPort;
01199     WORD               remoteControlPort;
01200 
01201     PIPSocket::Address remoteTransmitAddress;
01202 
01203     BOOL shutdownRead;
01204     BOOL shutdownWrite;
01205 
01206     PUDPSocket * dataSocket;
01207     PUDPSocket * controlSocket;
01208 
01209     BOOL appliedQOS;
01210 };
01211 
01212 
01213 #endif // __OPAL_RTP_H
01214 
01215 

Generated on Mon Sep 25 16:20:10 2006 for OPAL by  doxygen 1.4.7