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-2000 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 1.60  2006/01/26 03:35:03  shorne
00031  * Added more NAT traversal support
00032  *
00033  * Revision 1.59  2006/01/18 07:46:08  csoutheren
00034  * Initial version of RTP aggregation (disabled by default)
00035  *
00036  * Revision 1.58  2005/11/30 13:05:01  csoutheren
00037  * Changed tags for Doxygen
00038  *
00039  * Revision 1.57  2005/11/21 21:06:23  shorne
00040  * Added GQoS switches
00041  *
00042  * Revision 1.56  2005/08/27 02:06:00  csoutheren
00043  * Keep track of time first RTP packet is received
00044  *
00045  * Revision 1.55  2005/01/03 14:03:20  csoutheren
00046  * Added new configure options and ability to disable/enable modules
00047  *
00048  * Revision 1.54  2005/01/03 06:25:52  csoutheren
00049  * Added extensive support for disabling code modules at compile time
00050  *
00051  * Revision 1.53  2004/04/22 12:38:02  rjongbloed
00052  * Removed the RTP QoS class if there is no QoS support in build,
00053  *   thanks Nick Hoath, ISDN Communications Ltd.
00054  *
00055  * Revision 1.52  2004/04/07 05:31:42  csoutheren
00056  * Added ability to receive calls from endpoints behind NAT firewalls
00057  *
00058  * Revision 1.51  2003/10/27 06:03:39  csoutheren
00059  * Added support for QoS
00060  *   Thanks to Henry Harrison of AliceStreet
00061  *
00062  * Revision 1.50  2003/10/09 09:47:45  csoutheren
00063  * Fixed problem with re-opening RTP half-channels under unusual
00064  * circumstances. Thanks to Damien Sandras
00065  *
00066  * Revision 1.49  2003/05/14 13:46:39  rjongbloed
00067  * Removed hack of using special payload type for H.263 for a method which
00068  *   would be less prone to failure in the future.
00069  *
00070  * Revision 1.48  2003/05/02 04:57:43  robertj
00071  * Added header extension support to RTP data frame class.
00072  *
00073  * Revision 1.47  2003/05/02 04:21:53  craigs
00074  * Added hacked OpalH263 codec
00075  *
00076  * Revision 1.46  2003/02/07 00:30:41  robertj
00077  * Changes for bizarre usage of RTP code outside of scope of H.323 specs.
00078  *
00079  * Revision 1.45  2003/02/05 06:32:08  robertj
00080  * Fixed non-stun symmetric NAT support recently broken.
00081  *
00082  * Revision 1.44  2003/02/04 07:06:41  robertj
00083  * Added STUN support.
00084  *
00085  * Revision 1.43  2002/11/19 01:48:15  robertj
00086  * Allowed get/set of canonical anme and tool name.
00087  *
00088  * Revision 1.42  2002/11/12 22:10:48  robertj
00089  * Updated documentation.
00090  *
00091  * Revision 1.41  2002/10/31 00:33:29  robertj
00092  * Enhanced jitter buffer system so operates dynamically between minimum and
00093  *   maximum values. Altered API to assure app writers note the change!
00094  *
00095  * Revision 1.40  2002/09/26 04:01:58  robertj
00096  * Fixed calculation of fraction of packets lost in RR, thanks Awais Ali
00097  *
00098  * Revision 1.39  2002/09/16 01:14:15  robertj
00099  * Added #define so can select if #pragma interface/implementation is used on
00100  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00101  *
00102  * Revision 1.38  2002/09/03 05:47:02  robertj
00103  * Normalised the multi-include header prevention ifdef/define symbol.
00104  * Added copy constructor/operator for session manager.
00105  *
00106  * Revision 1.37  2002/08/05 10:03:47  robertj
00107  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00108  *
00109  * Revision 1.36  2002/05/28 02:37:37  robertj
00110  * Fixed reading data out of RTCP compound statements.
00111  *
00112  * Revision 1.35  2002/05/02 05:58:24  robertj
00113  * Changed the mechanism for sending RTCP reports so that they will continue
00114  *   to be sent regardless of if there is any actual data traffic.
00115  * Added support for compound RTCP statements for sender and receiver reports.
00116  *
00117  * Revision 1.34  2002/02/09 02:33:37  robertj
00118  * Improved payload type docuemntation and added Cisco CN.
00119  *
00120  * Revision 1.33  2002/01/22 07:08:26  robertj
00121  * Added IllegalPayloadType enum as need marker for none set
00122  *   and MaxPayloadType is a legal value.
00123  *
00124  * Revision 1.32  2001/11/09 05:39:54  craigs
00125  * Added initial T.38 support thanks to Adam Lazur
00126  *
00127  * Revision 1.31  2001/09/11 00:21:21  robertj
00128  * Fixed missing stack sizes in endpoint for cleaner thread and jitter thread.
00129  *
00130  * Revision 1.30  2001/07/06 06:32:22  robertj
00131  * Added flag and checks for RTP data having specific SSRC.
00132  * Changed transmitter IP address check so is based on first received
00133  *    PDU instead of expecting it to come from the host we are sending to.
00134  *
00135  * Revision 1.29  2001/06/04 11:37:48  robertj
00136  * Added thread safe enumeration functions of RTP sessions.
00137  * Added member access functions to UDP based RTP sessions.
00138  *
00139  * Revision 1.28  2001/04/24 06:15:50  robertj
00140  * Added work around for strange Cisco bug which suddenly starts sending
00141  *   RTP packets beginning at a difference sequence number base.
00142  *
00143  * Revision 1.27  2001/04/02 23:58:23  robertj
00144  * Added jitter calculation to RTP session.
00145  * Added trace of statistics.
00146  *
00147  * Revision 1.26  2001/02/09 05:16:24  robertj
00148  * Added #pragma interface for GNU C++.
00149  *
00150  * Revision 1.25  2000/12/18 08:58:30  craigs
00151  * Added ability set ports
00152  *
00153  * Revision 1.24  2000/09/25 01:44:31  robertj
00154  * Fixed possible race condition on shutdown of RTP session with jitter buffer.
00155  *
00156  * Revision 1.23  2000/09/21 02:06:06  craigs
00157  * Added handling for endpoints that return conformant, but useless, RTP address
00158  * and port numbers
00159  *
00160  * Revision 1.22  2000/05/23 12:57:28  robertj
00161  * Added ability to change IP Type Of Service code from applications.
00162  *
00163  * Revision 1.21  2000/05/18 11:53:34  robertj
00164  * Changes to support doc++ documentation generation.
00165  *
00166  * Revision 1.20  2000/05/04 11:49:21  robertj
00167  * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code.
00168  *
00169  * Revision 1.19  2000/05/02 04:32:25  robertj
00170  * Fixed copyright notice comment.
00171  *
00172  * Revision 1.18  2000/05/01 01:01:24  robertj
00173  * Added flag for what to do with out of orer packets (use if jitter, don't if not).
00174  *
00175  * Revision 1.17  2000/04/30 03:55:18  robertj
00176  * Improved the RTCP messages, epecially reports
00177  *
00178  * Revision 1.16  2000/04/10 17:39:21  robertj
00179  * Fixed debug output of RTP payload types to allow for unknown numbers.
00180  *
00181  * Revision 1.15  2000/04/05 03:17:31  robertj
00182  * Added more RTP statistics gathering and H.245 round trip delay calculation.
00183  *
00184  * Revision 1.14  2000/03/23 02:55:18  robertj
00185  * Added sending of SDES control packets.
00186  *
00187  * Revision 1.13  2000/03/20 20:54:04  robertj
00188  * Fixed problem with being able to reopen for reading an RTP_Session (Cisco compatibilty)
00189  *
00190  * Revision 1.12  2000/02/29 13:00:13  robertj
00191  * Added extra statistic display for RTP packets out of order.
00192  *
00193  * Revision 1.11  1999/12/30 09:14:31  robertj
00194  * Changed payload type functions to use enum.
00195  *
00196  * Revision 1.10  1999/12/23 23:02:35  robertj
00197  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00198  *
00199  * Revision 1.9  1999/11/20 05:35:57  robertj
00200  * Fixed possibly I/O block in RTP read loops.
00201  *
00202  * Revision 1.8  1999/11/19 09:17:15  robertj
00203  * Fixed problems with aycnhronous shut down of logical channels.
00204  *
00205  * Revision 1.7  1999/11/14 11:41:18  robertj
00206  * Added access functions to RTP statistics.
00207  *
00208  * Revision 1.6  1999/09/08 04:05:48  robertj
00209  * Added support for video capabilities & codec, still needs the actual codec itself!
00210  *
00211  * Revision 1.5  1999/08/31 12:34:18  robertj
00212  * Added gatekeeper support.
00213  *
00214  * Revision 1.4  1999/07/13 09:53:24  robertj
00215  * Fixed some problems with jitter buffer and added more debugging.
00216  *
00217  * Revision 1.3  1999/07/09 06:09:49  robertj
00218  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00219  *
00220  * Revision 1.2  1999/06/22 13:49:40  robertj
00221  * Added GSM support and further RTP protocol enhancements.
00222  *
00223  * Revision 1.1  1999/06/14 06:12:25  robertj
00224  * Changes for using RTP sessions correctly in H323 Logical Channel context
00225  *
00226  */
00227 
00228 #ifndef __OPAL_RTP_H
00229 #define __OPAL_RTP_H
00230 
00231 #ifdef P_USE_PRAGMA
00232 #pragma interface
00233 #endif
00234 
00235 #include <openh323buildopts.h>
00236 #include <ptlib/sockets.h>
00237 
00238 class RTP_JitterBuffer;
00239 class PHandleAggregator;
00240 
00241 #ifdef P_STUN
00242 class PNatMethod;
00243 #endif
00244 
00246 // 
00247 // class to hold the QoS definitions for an RTP channel
00248 
00249 #if P_HAS_QOS
00250 
00251 class RTP_QOS : public PObject
00252 {
00253   PCLASSINFO(RTP_QOS,PObject);
00254   public:
00255     PQoS dataQoS;
00256     PQoS ctrlQoS;
00257 };
00258 
00259 #else
00260 
00261 class RTP_QOS;
00262 
00263 #endif
00264 
00266 // Real Time Protocol - IETF RFC1889 and RFC1890
00267 
00270 class RTP_DataFrame : public PBYTEArray
00271 {
00272   PCLASSINFO(RTP_DataFrame, PBYTEArray);
00273 
00274   public:
00275     RTP_DataFrame(PINDEX payloadSize = 2048);
00276 
00277     enum {
00278       ProtocolVersion = 2,
00279       MinHeaderSize = 12
00280     };
00281 
00282     enum PayloadTypes {
00283       PCMU,         // G.711 u-Law
00284       FS1016,       // Federal Standard 1016 CELP
00285       G721,         // ADPCM - Subsumed by G.726
00286       G726 = G721,
00287       GSM,          // GSM 06.10
00288       G7231,        // G.723.1 at 6.3kbps or 5.3 kbps
00289       DVI4_8k,      // DVI4 at 8kHz sample rate
00290       DVI4_16k,     // DVI4 at 16kHz sample rate
00291       LPC,          // LPC-10 Linear Predictive CELP
00292       PCMA,         // G.711 A-Law
00293       G722,         // G.722
00294       L16_Stereo,   // 16 bit linear PCM
00295       L16_Mono,     // 16 bit linear PCM
00296       G723,         // G.723
00297       CN,           // Confort Noise
00298       MPA,          // MPEG1 or MPEG2 audio
00299       G728,         // G.728 16kbps CELP
00300       DVI4_11k,     // DVI4 at 11kHz sample rate
00301       DVI4_22k,     // DVI4 at 22kHz sample rate
00302       G729,         // G.729 8kbps
00303       Cisco_CN,     // Cisco systems comfort noise (unofficial)
00304 
00305       CelB = 25,    // Sun Systems Cell-B video
00306       JPEG,         // Motion JPEG
00307       H261 = 31,    // H.261
00308       MPV,          // MPEG1 or MPEG2 video
00309       MP2T,         // MPEG2 transport system
00310       H263,         // H.263
00311 
00312       LastKnownPayloadType,
00313 
00314       DynamicBase = 96,
00315       MaxPayloadType = 127,
00316       IllegalPayloadType
00317     };
00318 
00319     unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00320 
00321     BOOL GetExtension() const   { return (theArray[0]&0x10) != 0; }
00322     void SetExtension(BOOL ext);
00323 
00324     BOOL GetMarker() const { return (theArray[1]&0x80) != 0; }
00325     void SetMarker(BOOL m);
00326 
00327     PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00328     void         SetPayloadType(PayloadTypes t);
00329 
00330     WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00331     void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00332 
00333     DWORD GetTimestamp() const  { return *(PUInt32b *)&theArray[4]; }
00334     void  SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00335 
00336     DWORD GetSyncSource() const  { return *(PUInt32b *)&theArray[8]; }
00337     void  SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00338 
00339     PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00340     DWORD  GetContribSource(PINDEX idx) const;
00341     void   SetContribSource(PINDEX idx, DWORD src);
00342 
00343     PINDEX GetHeaderSize() const;
00344 
00345     int GetExtensionType() const; // -1 is no extension
00346     void   SetExtensionType(int type);
00347     PINDEX GetExtensionSize() const;
00348     BOOL   SetExtensionSize(PINDEX sz);
00349     BYTE * GetExtensionPtr() const;
00350 
00351     PINDEX GetPayloadSize() const { return payloadSize; }
00352     BOOL   SetPayloadSize(PINDEX sz);
00353     BYTE * GetPayloadPtr()     const { return (BYTE *)(theArray+GetHeaderSize()); }
00354 
00355   protected:
00356     PINDEX payloadSize;
00357 
00358 #if PTRACING
00359     friend ostream & operator<<(ostream & o, PayloadTypes t);
00360 #endif
00361 };
00362 
00363 PLIST(RTP_DataFrameList, RTP_DataFrame);
00364 
00365 
00368 class RTP_ControlFrame : public PBYTEArray
00369 {
00370   PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00371 
00372   public:
00373     RTP_ControlFrame(PINDEX compoundSize = 2048);
00374 
00375     unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00376 
00377     unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00378     void     SetCount(unsigned count);
00379 
00380     enum PayloadTypes {
00381       e_SenderReport = 200,
00382       e_ReceiverReport,
00383       e_SourceDescription,
00384       e_Goodbye,
00385       e_ApplDefined
00386     };
00387 
00388     unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00389     void     SetPayloadType(unsigned t);
00390 
00391     PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00392     void   SetPayloadSize(PINDEX sz);
00393 
00394     BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+compoundOffset+4); }
00395 
00396     BOOL ReadNextCompound();
00397     BOOL WriteNextCompound();
00398 
00399     PINDEX GetCompoundSize() const { return compoundSize; }
00400 
00401 #pragma pack(1)
00402     struct ReceiverReport {
00403       PUInt32b ssrc;      /* data source being reported */
00404       BYTE fraction;      /* fraction lost since last SR/RR */
00405       BYTE lost[3];       /* cumulative number of packets lost (signed!) */
00406       PUInt32b last_seq;  /* extended last sequence number received */
00407       PUInt32b jitter;    /* interarrival jitter */
00408       PUInt32b lsr;       /* last SR packet from this source */
00409       PUInt32b dlsr;      /* delay since last SR packet */
00410 
00411       unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00412       void SetLostPackets(unsigned lost);
00413     };
00414 
00415     struct SenderReport {
00416       PUInt32b ssrc;      /* source this RTCP packet refers to */
00417       PUInt32b ntp_sec;   /* NTP timestamp */
00418       PUInt32b ntp_frac;
00419       PUInt32b rtp_ts;    /* RTP timestamp */
00420       PUInt32b psent;     /* packets sent */
00421       PUInt32b osent;     /* octets sent */ 
00422     };
00423 
00424     enum DescriptionTypes {
00425       e_END,
00426       e_CNAME,
00427       e_NAME,
00428       e_EMAIL,
00429       e_PHONE,
00430       e_LOC,
00431       e_TOOL,
00432       e_NOTE,
00433       e_PRIV,
00434       NumDescriptionTypes
00435     };
00436 
00437     struct SourceDescription {
00438       PUInt32b src;       /* first SSRC/CSRC */
00439       struct Item {
00440         BYTE type;        /* type of SDES item (enum DescriptionTypes) */
00441         BYTE length;      /* length of SDES item (in octets) */
00442         char data[1];     /* text, not zero-terminated */
00443 
00444         const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00445         Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00446       } item[1];          /* list of SDES items */
00447     };
00448 
00449     SourceDescription & AddSourceDescription(
00450       DWORD src   
00451     );
00452 
00453     SourceDescription::Item & AddSourceDescriptionItem(
00454       SourceDescription & sdes, 
00455       unsigned type,            
00456       const PString & data      
00457     );
00458 #pragma pack()
00459 
00460   protected:
00461     PINDEX compoundOffset;
00462     PINDEX compoundSize;
00463 };
00464 
00465 
00466 class RTP_Session;
00467 
00472 class RTP_UserData : public PObject
00473 {
00474   PCLASSINFO(RTP_UserData, PObject);
00475 
00476   public:
00483     virtual void OnTxStatistics(
00484       const RTP_Session & session   
00485     ) const;
00486 
00493     virtual void OnRxStatistics(
00494       const RTP_Session & session   
00495     ) const;
00496 };
00497 
00498 
00501 class RTP_Session : public PObject
00502 {
00503   PCLASSINFO(RTP_Session, PObject);
00504 
00505   public:
00506     enum {
00507       DefaultAudioSessionID = 1,
00508       DefaultVideoSessionID = 2,
00509       DefaultFaxSessionID = 3
00510     };
00511 
00516     RTP_Session(
00517 #ifdef H323_RTP_AGGREGATE
00518       PHandleAggregator * aggregator, 
00519 #endif
00520       unsigned id,                    
00521       RTP_UserData * userData = NULL  
00522     );
00523 
00527     ~RTP_Session();
00529 
00541     void SetJitterBufferSize(
00542       unsigned minJitterDelay, 
00543       unsigned maxJitterDelay, 
00544       PINDEX stackSize = 30000 
00545     );
00546 
00552     unsigned GetJitterBufferSize() const;
00553 
00555     virtual BOOL ModifyQOS(RTP_QOS * )
00556     { return FALSE; }
00557 
00563     BOOL ReadBufferedData(
00564       DWORD timestamp,        
00565       RTP_DataFrame & frame   
00566     );
00567 
00573     virtual BOOL ReadData(
00574       RTP_DataFrame & frame,   
00575       BOOL loop                
00576     ) = 0;
00577 
00580     virtual BOOL WriteData(
00581       RTP_DataFrame & frame   
00582     ) = 0;
00583 
00586     virtual BOOL WriteControl(
00587       RTP_ControlFrame & frame    
00588     ) = 0;
00589 
00592     virtual BOOL SendReport();
00593 
00596     virtual void Close(
00597       BOOL reading    
00598     ) = 0;
00599 
00602     virtual PString GetLocalHostName() = 0;
00604 
00607     enum SendReceiveStatus {
00608       e_ProcessPacket,
00609       e_IgnorePacket,
00610       e_AbortTransport
00611     };
00612     virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00613     virtual SendReceiveStatus OnReceiveData(const RTP_DataFrame & frame);
00614     virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00615 
00616     class ReceiverReport : public PObject  {
00617         PCLASSINFO(ReceiverReport, PObject);
00618       public:
00619         void PrintOn(ostream &) const;
00620 
00621         DWORD sourceIdentifier;
00622         DWORD fractionLost;         /* fraction lost since last SR/RR */
00623         DWORD totalLost;            /* cumulative number of packets lost (signed!) */
00624         DWORD lastSequenceNumber;   /* extended last sequence number received */
00625         DWORD jitter;               /* interarrival jitter */
00626         PTimeInterval lastTimestamp;/* last SR packet from this source */
00627         PTimeInterval delay;        /* delay since last SR packet */
00628     };
00629     PARRAY(ReceiverReportArray, ReceiverReport);
00630 
00631     class SenderReport : public PObject  {
00632         PCLASSINFO(SenderReport, PObject);
00633       public:
00634         void PrintOn(ostream &) const;
00635 
00636         DWORD sourceIdentifier;
00637         PTime realTimestamp;
00638         DWORD rtpTimestamp;
00639         DWORD packetsSent;
00640         DWORD octetsSent;
00641     };
00642     virtual void OnRxSenderReport(const SenderReport & sender,
00643                                   const ReceiverReportArray & reports);
00644     virtual void OnRxReceiverReport(DWORD src,
00645                                     const ReceiverReportArray & reports);
00646 
00647     class SourceDescription : public PObject  {
00648         PCLASSINFO(SourceDescription, PObject);
00649       public:
00650         SourceDescription(DWORD src) { sourceIdentifier = src; }
00651         void PrintOn(ostream &) const;
00652 
00653         DWORD            sourceIdentifier;
00654         POrdinalToString items;
00655     };
00656     PARRAY(SourceDescriptionArray, SourceDescription);
00657     virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00658 
00659     virtual void OnRxGoodbye(const PDWORDArray & sources,
00660                              const PString & reason);
00661 
00662     virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00663                                  const BYTE * data, PINDEX size);
00665 
00670     unsigned GetSessionID() const { return sessionID; }
00671 
00674     PString GetCanonicalName() const;
00675 
00678     void SetCanonicalName(const PString & name);
00679 
00682     PString GetToolName() const;
00683 
00686     void SetToolName(const PString & name);
00687 
00690     RTP_UserData * GetUserData() const { return userData; }
00691 
00694     void SetUserData(
00695       RTP_UserData * data   
00696     );
00697 
00700     DWORD GetSyncSourceOut() const { return syncSourceOut; }
00701 
00704     void IncrementReference() { referenceCount++; }
00705 
00708     BOOL DecrementReference() { return --referenceCount == 0; }
00709 
00712     BOOL WillIgnoreOtherSources() const { return ignoreOtherSources; }
00713 
00716     void SetIgnoreOtherSources(
00717       BOOL ignore   
00718     ) { ignoreOtherSources = ignore; }
00719 
00722     BOOL WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00723 
00726     void SetIgnoreOutOfOrderPackets(
00727       BOOL ignore   
00728     ) { ignoreOutOfOrderPackets = ignore; }
00729 
00732     const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00733 
00736     void SetReportTimeInterval(
00737       const PTimeInterval & interval 
00738     )  { reportTimeInterval = interval; }
00739 
00742     PTimeInterval GetReportTimer()
00743     { return reportTimer; }
00744 
00747     unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00748 
00751     void SetTxStatisticsInterval(
00752       unsigned packets   
00753     );
00754 
00757     unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00758 
00761     void SetRxStatisticsInterval(
00762       unsigned packets   
00763     );
00764 
00767     DWORD GetPacketsSent() const { return packetsSent; }
00768 
00771     DWORD GetOctetsSent() const { return octetsSent; }
00772 
00775     DWORD GetPacketsReceived() const { return packetsReceived; }
00776 
00779     DWORD GetOctetsReceived() const { return octetsReceived; }
00780 
00783     DWORD GetPacketsLost() const { return packetsLost; }
00784 
00787     DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00788 
00791     DWORD GetPacketsTooLate() const;
00792 
00797     DWORD GetAverageSendTime() const { return averageSendTime; }
00798 
00803     DWORD GetMaximumSendTime() const { return maximumSendTime; }
00804 
00809     DWORD GetMinimumSendTime() const { return minimumSendTime; }
00810 
00815     DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00816 
00821     DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00822 
00827     DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00828 
00833     DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00834 
00838     DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00839 
00843     PTime GetFirstDataReceivedTime() const { return firstDataReceivedTime; }
00845 
00848     virtual int GetDataSocketHandle() const
00849     { return -1; }
00850     virtual int GetControlSocketHandle() const
00851     { return -1; }
00853 
00854   protected:
00855     void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00856 
00857     unsigned           sessionID;
00858     PString            canonicalName;
00859     PString            toolName;
00860     unsigned           referenceCount;
00861     RTP_UserData     * userData;
00862 
00863 #ifndef NO_H323_AUDIO_CODECS
00864     RTP_JitterBuffer * jitter;
00865 #endif
00866 
00867     BOOL          ignoreOtherSources;
00868     BOOL          ignoreOutOfOrderPackets;
00869     DWORD         syncSourceOut;
00870     DWORD         syncSourceIn;
00871     PTimeInterval reportTimeInterval;
00872     unsigned      txStatisticsInterval;
00873     unsigned      rxStatisticsInterval;
00874     WORD          lastSentSequenceNumber;
00875     WORD          expectedSequenceNumber;
00876     DWORD         lastSentTimestamp;
00877     PTimeInterval lastSentPacketTime;
00878     PTimeInterval lastReceivedPacketTime;
00879     WORD          lastRRSequenceNumber;
00880     PINDEX        consecutiveOutOfOrderPackets;
00881 
00882     // Statistics
00883     DWORD packetsSent;
00884     DWORD octetsSent;
00885     DWORD packetsReceived;
00886     DWORD octetsReceived;
00887     DWORD packetsLost;
00888     DWORD packetsOutOfOrder;
00889     DWORD averageSendTime;
00890     DWORD maximumSendTime;
00891     DWORD minimumSendTime;
00892     DWORD averageReceiveTime;
00893     DWORD maximumReceiveTime;
00894     DWORD minimumReceiveTime;
00895     DWORD jitterLevel;
00896     DWORD maximumJitterLevel;
00897 
00898     unsigned txStatisticsCount;
00899     unsigned rxStatisticsCount;
00900 
00901     DWORD    averageSendTimeAccum;
00902     DWORD    maximumSendTimeAccum;
00903     DWORD    minimumSendTimeAccum;
00904     DWORD    averageReceiveTimeAccum;
00905     DWORD    maximumReceiveTimeAccum;
00906     DWORD    minimumReceiveTimeAccum;
00907     DWORD    packetsLostSinceLastRR;
00908     DWORD    lastTransitTime;
00909     PTime    firstDataReceivedTime;
00910 
00911     PMutex reportMutex;
00912     PTimer reportTimer;
00913 
00914 #ifdef H323_RTP_AGGREGATE
00915     PHandleAggregator * aggregator;
00916 #endif
00917 };
00918 
00919 
00922 class RTP_SessionManager : public PObject
00923 {
00924   PCLASSINFO(RTP_SessionManager, PObject);
00925 
00926   public:
00931     RTP_SessionManager();
00932     RTP_SessionManager(const RTP_SessionManager & sm);
00933     RTP_SessionManager & operator=(const RTP_SessionManager & sm);
00935 
00936 
00950     RTP_Session * UseSession(
00951       unsigned sessionID    
00952     );
00953 
00960     void AddSession(
00961       RTP_Session * session    
00962     );
00963 
00967     void ReleaseSession(
00968       unsigned sessionID    
00969     );
00970 
00975     RTP_Session * GetSession(
00976       unsigned sessionID    
00977     ) const;
00978 
00995     RTP_Session * First();
00996 
01003     RTP_Session * Next();
01004 
01012     void Exit();
01014 
01015 
01016   protected:
01017     PDICTIONARY(SessionDict, POrdinalKey, RTP_Session);
01018     SessionDict sessions;
01019     PMutex      mutex;
01020     PINDEX      enumerationIndex;
01021 };
01022 
01023 
01024 
01027 class RTP_UDP : public RTP_Session
01028 {
01029   PCLASSINFO(RTP_UDP, RTP_Session);
01030 
01031   public:
01036     RTP_UDP(
01037 #ifdef H323_RTP_AGGREGATE
01038       PHandleAggregator * aggregator, 
01039 #endif
01040       unsigned id,                    
01041       BOOL remoteIsNat = FALSE        
01042     );
01043 
01045     ~RTP_UDP();
01047 
01055     virtual BOOL ReadData(RTP_DataFrame & frame, BOOL loop);
01056 
01059     virtual BOOL WriteData(RTP_DataFrame & frame);
01060 
01063     virtual BOOL WriteControl(RTP_ControlFrame & frame);
01064 
01067     virtual void Close(
01068       BOOL reading    
01069     );
01070 
01073     virtual PString GetLocalHostName();
01075 
01080     virtual BOOL ModifyQOS(RTP_QOS * rtpqos);
01081 
01084      virtual void EnableGQoS();
01085 
01086 #if P_HAS_QOS
01087 
01089       PQoS & GetQOS();
01090 #endif
01091 
01092 
01097     BOOL Open(
01098       PIPSocket::Address localAddress,  
01099       WORD portBase,                    
01100       WORD portMax,                     
01101       BYTE ipTypeOfService,             
01102 #ifdef P_STUN
01103      PNatMethod * meth = NULL,          
01104 #else
01105       void * = NULL,                    
01106 #endif
01107       RTP_QOS * rtpqos = NULL           
01108     );
01110 
01113     void Reopen(BOOL isReading);
01115 
01120     PIPSocket::Address GetLocalAddress() const { return localAddress; }
01121 
01124     void SetLocalAddress(
01125       const PIPSocket::Address & addr
01126     ) { localAddress = addr; }
01127 
01130     PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01131 
01134     WORD GetLocalDataPort() const { return localDataPort; }
01135 
01138     WORD GetLocalControlPort() const { return localControlPort; }
01139 
01142     WORD GetRemoteDataPort() const { return remoteDataPort; }
01143 
01146     WORD GetRemoteControlPort() const { return remoteControlPort; }
01147 
01150     PUDPSocket & GetDataSocket() { return *dataSocket; }
01151 
01154     PUDPSocket & GetControlSocket() { return *controlSocket; }
01155 
01158     BOOL SetRemoteSocketInfo(
01159       PIPSocket::Address address,   
01160       WORD port,                    
01161       BOOL isDataPort               
01162     );
01163 
01166     void ApplyQOS(
01167       const PIPSocket::Address & addr
01168     );
01170 
01171     int GetDataSocketHandle() const
01172     { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01173 
01174     int GetControlSocketHandle() const
01175     { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01176 
01177   protected:
01178     SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01179     SendReceiveStatus ReadControlPDU();
01180     SendReceiveStatus ReadDataOrControlPDU(
01181       PUDPSocket & socket,
01182       PBYTEArray & frame,
01183       BOOL fromDataChannel
01184     );
01185 
01186     PIPSocket::Address localAddress;
01187     WORD               localDataPort;
01188     WORD               localControlPort;
01189 
01190     PIPSocket::Address remoteAddress;
01191     WORD               remoteDataPort;
01192     WORD               remoteControlPort;
01193 
01194     PIPSocket::Address remoteTransmitAddress;
01195 
01196     BOOL shutdownRead;
01197     BOOL shutdownWrite;
01198 
01199     PUDPSocket * dataSocket;
01200     PUDPSocket * controlSocket;
01201 
01202     BOOL appliedQOS;
01203     BOOL enableGQOS;
01204 
01205     BOOL remoteIsNAT;
01206 };
01207 
01208 
01209 #endif // __OPAL_RTP_H
01210 
01211 

Generated on Wed Feb 6 09:02:45 2008 for OpenH323 by  doxygen 1.5.4