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

Generated on Fri Jan 25 01:20:18 2008 for OPAL by  doxygen 1.5.4