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  * $Revision: 20896 $
00030  * $Author: csoutheren $
00031  * $Date: 2008-09-08 05:51:37 +0000 (Mon, 08 Sep 2008) $
00032  */
00033 
00034 #ifndef __OPAL_RTP_H
00035 #define __OPAL_RTP_H
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 #include <opal/buildopts.h>
00042 #include <ptlib/sockets.h>
00043 
00044 
00045 class RTP_JitterBuffer;
00046 class PNatMethod;
00047 class OpalSecurityMode;
00048 
00049 #if OPAL_RTP_AGGREGATE
00050 #include <ptclib/sockagg.h>
00051 #else
00052 typedef void * PHandleAggregator;
00053 typedef void * RTP_AggregatedHandle;
00054 #endif
00055 
00057 // 
00058 // class to hold the QoS definitions for an RTP channel
00059 
00060 class RTP_QOS : public PObject
00061 {
00062   PCLASSINFO(RTP_QOS,PObject);
00063   public:
00064     PQoS dataQoS;
00065     PQoS ctrlQoS;
00066 };
00067 
00069 // Real Time Protocol - IETF RFC1889 and RFC1890
00070 
00073 class RTP_DataFrame : public PBYTEArray
00074 {
00075   PCLASSINFO(RTP_DataFrame, PBYTEArray);
00076 
00077   public:
00078     RTP_DataFrame(PINDEX payloadSize = 2048);
00079     RTP_DataFrame(const BYTE * data, PINDEX len, PBoolean dynamic = PTrue);
00080 
00081     enum {
00082       ProtocolVersion = 2,
00083       MinHeaderSize = 12,
00084       // Max safe MTU size (576 bytes as per RFC879) minus IP, UDP an RTP headers
00085       MaxMtuPayloadSize = (576-20-16-12)
00086     };
00087 
00088     enum PayloadTypes {
00089       PCMU,         // G.711 u-Law
00090       FS1016,       // Federal Standard 1016 CELP
00091       G721,         // ADPCM - Subsumed by G.726
00092       G726 = G721,
00093       GSM,          // GSM 06.10
00094       G7231,        // G.723.1 at 6.3kbps or 5.3 kbps
00095       DVI4_8k,      // DVI4 at 8kHz sample rate
00096       DVI4_16k,     // DVI4 at 16kHz sample rate
00097       LPC,          // LPC-10 Linear Predictive CELP
00098       PCMA,         // G.711 A-Law
00099       G722,         // G.722
00100       L16_Stereo,   // 16 bit linear PCM
00101       L16_Mono,     // 16 bit linear PCM
00102       G723,         // G.723
00103       CN,           // Confort Noise
00104       MPA,          // MPEG1 or MPEG2 audio
00105       G728,         // G.728 16kbps CELP
00106       DVI4_11k,     // DVI4 at 11kHz sample rate
00107       DVI4_22k,     // DVI4 at 22kHz sample rate
00108       G729,         // G.729 8kbps
00109       Cisco_CN,     // Cisco systems comfort noise (unofficial)
00110 
00111       CelB = 25,    // Sun Systems Cell-B video
00112       JPEG,         // Motion JPEG
00113       H261 = 31,    // H.261
00114       MPV,          // MPEG1 or MPEG2 video
00115       MP2T,         // MPEG2 transport system
00116       H263,         // H.263
00117 
00118       LastKnownPayloadType,
00119 
00120       DynamicBase = 96,
00121       MaxPayloadType = 127,
00122       IllegalPayloadType
00123     };
00124 
00125     unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00126 
00127     PBoolean GetExtension() const   { return (theArray[0]&0x10) != 0; }
00128     void SetExtension(PBoolean ext);
00129 
00130     PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00131     void SetMarker(PBoolean m);
00132 
00133     bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00134     void SetPadding(bool v)  { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00135 
00136     unsigned GetPaddingSize() const;
00137 
00138     PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00139     void         SetPayloadType(PayloadTypes t);
00140 
00141     WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00142     void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00143 
00144     DWORD GetTimestamp() const  { return *(PUInt32b *)&theArray[4]; }
00145     void  SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00146 
00147     DWORD GetSyncSource() const  { return *(PUInt32b *)&theArray[8]; }
00148     void  SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00149 
00150     PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00151     DWORD  GetContribSource(PINDEX idx) const;
00152     void   SetContribSource(PINDEX idx, DWORD src);
00153 
00154     PINDEX GetHeaderSize() const;
00155 
00156     int GetExtensionType() const; // -1 is no extension
00157     void   SetExtensionType(int type);
00158     PINDEX GetExtensionSize() const;
00159     PBoolean   SetExtensionSize(PINDEX sz);
00160     BYTE * GetExtensionPtr() const;
00161 
00162     PINDEX GetPayloadSize() const { return payloadSize - GetPaddingSize(); }
00163     PBoolean   SetPayloadSize(PINDEX sz);
00164     BYTE * GetPayloadPtr()     const { return (BYTE *)(theArray+GetHeaderSize()); }
00165 
00166     virtual void PrintOn(ostream & strm) const;
00167 
00168   protected:
00169     PINDEX payloadSize;
00170 
00171 #if PTRACING
00172     friend ostream & operator<<(ostream & o, PayloadTypes t);
00173 #endif
00174 };
00175 
00176 PLIST(RTP_DataFrameList, RTP_DataFrame);
00177 
00178 
00181 class RTP_ControlFrame : public PBYTEArray
00182 {
00183   PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00184 
00185   public:
00186     RTP_ControlFrame(PINDEX compoundSize = 2048);
00187 
00188     unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00189 
00190     unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00191     void     SetCount(unsigned count);
00192 
00193     enum PayloadTypes {
00194       e_IntraFrameRequest = 192,
00195       e_SenderReport = 200,
00196       e_ReceiverReport,
00197       e_SourceDescription,
00198       e_Goodbye,
00199       e_ApplDefined
00200     };
00201 
00202     unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00203     void     SetPayloadType(unsigned t);
00204 
00205     PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00206     void   SetPayloadSize(PINDEX sz);
00207 
00208     BYTE * GetPayloadPtr() const;
00209 
00210     PBoolean ReadNextPacket();
00211     PBoolean StartNewPacket();
00212     void EndPacket();
00213 
00214     PINDEX GetCompoundSize() const;
00215 
00216     void Reset(PINDEX size);
00217 
00218 #pragma pack(1)
00219     struct ReceiverReport {
00220       PUInt32b ssrc;      /* data source being reported */
00221       BYTE fraction;      /* fraction lost since last SR/RR */
00222       BYTE lost[3];       /* cumulative number of packets lost (signed!) */
00223       PUInt32b last_seq;  /* extended last sequence number received */
00224       PUInt32b jitter;    /* interarrival jitter */
00225       PUInt32b lsr;       /* last SR packet from this source */
00226       PUInt32b dlsr;      /* delay since last SR packet */
00227 
00228       unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00229       void SetLostPackets(unsigned lost);
00230     };
00231 
00232     struct SenderReport {
00233       PUInt32b ntp_sec;   /* NTP timestamp */
00234       PUInt32b ntp_frac;
00235       PUInt32b rtp_ts;    /* RTP timestamp */
00236       PUInt32b psent;     /* packets sent */
00237       PUInt32b osent;     /* octets sent */ 
00238     };
00239 
00240     enum DescriptionTypes {
00241       e_END,
00242       e_CNAME,
00243       e_NAME,
00244       e_EMAIL,
00245       e_PHONE,
00246       e_LOC,
00247       e_TOOL,
00248       e_NOTE,
00249       e_PRIV,
00250       NumDescriptionTypes
00251     };
00252 
00253     struct SourceDescription {
00254       PUInt32b src;       /* first SSRC/CSRC */
00255       struct Item {
00256         BYTE type;        /* type of SDES item (enum DescriptionTypes) */
00257         BYTE length;      /* length of SDES item (in octets) */
00258         char data[1];     /* text, not zero-terminated */
00259 
00260         /* WARNING, SourceDescription may not be big enough to contain length and data, for 
00261            instance, when type == RTP_ControlFrame::e_END.
00262            Be careful whan calling the following function of it may read to over to 
00263            memory allocated*/
00264         unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);} 
00265         const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00266         Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00267       } item[1];          /* list of SDES items */
00268     };
00269 
00270     void StartSourceDescription(
00271       DWORD src   
00272     );
00273 
00274     void AddSourceDescriptionItem(
00275       unsigned type,            
00276       const PString & data      
00277     );
00278 #pragma pack()
00279 
00280   protected:
00281     PINDEX compoundOffset;
00282     PINDEX payloadSize;
00283 };
00284 
00285 
00286 class RTP_Session;
00287 
00289 
00290 #ifdef OPAL_STATISTICS
00291 
00294 class OpalMediaStatistics : public PObject
00295 {
00296     PCLASSINFO(OpalMediaStatistics, PObject);
00297   public:
00298     OpalMediaStatistics();
00299 
00300     // General info (typicallly from RTP)
00301     PUInt64  m_totalBytes;
00302     unsigned m_totalPackets;
00303     unsigned m_packetsLost;
00304     unsigned m_packetsOutOfOrder;
00305     unsigned m_packetsTooLate;
00306     unsigned m_packetOverruns;
00307     unsigned m_minimumPacketTime;
00308     unsigned m_averagePacketTime;
00309     unsigned m_maximumPacketTime;
00310 
00311     // Audio
00312     unsigned m_averageJitter;
00313     unsigned m_maximumJitter;
00314 
00315     // Video
00316     unsigned m_totalFrames;
00317     unsigned m_keyFrames;
00318 };
00319 
00320 #endif
00321 
00322 
00327 class RTP_UserData : public PObject
00328 {
00329   PCLASSINFO(RTP_UserData, PObject);
00330 
00331   public:
00338     virtual void OnTxStatistics(
00339       const RTP_Session & session   
00340     ) const;
00341 
00348     virtual void OnRxStatistics(
00349       const RTP_Session & session   
00350     ) const;
00351 
00352 #if OPAL_VIDEO
00353 
00358     virtual void OnTxIntraFrameRequest(
00359       const RTP_Session & session   
00360     ) const;
00361 
00367     virtual void OnRxIntraFrameRequest(
00368       const RTP_Session & session   
00369     ) const;
00370 #endif
00371 
00375     virtual void OnClearCall(
00376       const RTP_Session & session   
00377     );
00378 };
00379 
00380 class RTP_Encoding;
00381 
00382 
00385 class RTP_Session : public PObject
00386 {
00387   PCLASSINFO(RTP_Session, PObject);
00388 
00389   public:
00394     RTP_Session(
00395       const PString & encoding,            
00396 #if OPAL_RTP_AGGREGATE
00397       PHandleAggregator * aggregator,      
00398 #endif
00399       unsigned id,                         
00400       RTP_UserData * userData = NULL,      
00401       PBoolean autoDeleteUserData = PTrue  
00402     );
00403 
00407     ~RTP_Session();
00409 
00421     void SetJitterBufferSize(
00422       unsigned minJitterDelay, 
00423       unsigned maxJitterDelay, 
00424       unsigned timeUnits = 8,  
00425       PINDEX stackSize = 30000 
00426     );
00427 
00433     unsigned GetJitterBufferSize() const;
00434     
00437     unsigned GetJitterTimeUnits() const;
00438 
00440     virtual PBoolean ModifyQOS(RTP_QOS * )
00441     { return PFalse; }
00442 
00448     virtual PBoolean ReadBufferedData(
00449       RTP_DataFrame & frame   
00450     );
00451 
00457     virtual PBoolean ReadData(
00458       RTP_DataFrame & frame,  
00459       PBoolean loop               
00460     ) = 0;
00461 
00464     virtual PBoolean WriteData(
00465       RTP_DataFrame & frame   
00466     ) = 0;
00467 
00471     virtual PBoolean WriteOOBData(
00472       RTP_DataFrame & frame,
00473       bool rewriteTimeStamp = true
00474     );
00475 
00478     virtual PBoolean WriteControl(
00479       RTP_ControlFrame & frame    
00480     ) = 0;
00481 
00484     virtual PBoolean SendReport();
00485 
00488     virtual void Close(
00489       PBoolean reading    
00490     ) = 0;
00491 
00494     virtual void Reopen(
00495       PBoolean isReading
00496     ) = 0;
00497 
00500     virtual PString GetLocalHostName() = 0;
00501 
00502 #ifdef OPAL_STATISTICS
00503     virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00504 #endif
00505 
00506 
00509     enum SendReceiveStatus {
00510       e_ProcessPacket,
00511       e_IgnorePacket,
00512       e_AbortTransport
00513     };
00514     virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00515     virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00516 
00517     virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00518     virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00519 
00520     virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00521     virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00522 
00523     virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00524 
00525     class ReceiverReport : public PObject  {
00526         PCLASSINFO(ReceiverReport, PObject);
00527       public:
00528         void PrintOn(ostream &) const;
00529 
00530         DWORD sourceIdentifier;
00531         DWORD fractionLost;         /* fraction lost since last SR/RR */
00532         DWORD totalLost;            /* cumulative number of packets lost (signed!) */
00533         DWORD lastSequenceNumber;   /* extended last sequence number received */
00534         DWORD jitter;               /* interarrival jitter */
00535         PTimeInterval lastTimestamp;/* last SR packet from this source */
00536         PTimeInterval delay;        /* delay since last SR packet */
00537     };
00538     PARRAY(ReceiverReportArray, ReceiverReport);
00539 
00540     class SenderReport : public PObject  {
00541         PCLASSINFO(SenderReport, PObject);
00542       public:
00543         void PrintOn(ostream &) const;
00544 
00545         DWORD sourceIdentifier;
00546         PTime realTimestamp;
00547         DWORD rtpTimestamp;
00548         DWORD packetsSent;
00549         DWORD octetsSent;
00550     };
00551     virtual void OnRxSenderReport(const SenderReport & sender,
00552                                   const ReceiverReportArray & reports);
00553     virtual void OnRxReceiverReport(DWORD src,
00554                                     const ReceiverReportArray & reports);
00555 
00556     class SourceDescription : public PObject  {
00557         PCLASSINFO(SourceDescription, PObject);
00558       public:
00559         SourceDescription(DWORD src) { sourceIdentifier = src; }
00560         void PrintOn(ostream &) const;
00561 
00562         DWORD            sourceIdentifier;
00563         POrdinalToString items;
00564     };
00565     PARRAY(SourceDescriptionArray, SourceDescription);
00566     virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00567 
00568     virtual void OnRxGoodbye(const PDWORDArray & sources,
00569                              const PString & reason);
00570 
00571     virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00572                                  const BYTE * data, PINDEX size);
00574 
00579     unsigned GetSessionID() const { return sessionID; }
00580 
00583     bool IsAudio() const { return isAudio; }
00584 
00587     void SetAudio(
00588       bool aud    
00589     ) { isAudio = aud; }
00590 
00593     PString GetCanonicalName() const;
00594 
00597     void SetCanonicalName(const PString & name);
00598 
00601     PString GetToolName() const;
00602 
00605     void SetToolName(const PString & name);
00606 
00609     RTP_UserData * GetUserData() const { return userData; }
00610 
00613     void SetUserData(
00614       RTP_UserData * data,            
00615       PBoolean autoDeleteUserData = PTrue  
00616     );
00617 
00620     DWORD GetSyncSourceOut() const { return syncSourceOut; }
00621 
00624     bool AllowAnySyncSource() const { return allowAnySyncSource; }
00625 
00628     void SetAnySyncSource(
00629       bool allow    
00630     ) { allowAnySyncSource = allow; }
00631 
00634     PBoolean WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00635 
00638     void SetIgnoreOutOfOrderPackets(
00639       PBoolean ignore   
00640     ) { ignoreOutOfOrderPackets = ignore; }
00641 
00644     void SetIgnorePayloadTypeChanges(
00645       PBoolean ignore   
00646     ) { ignorePayloadTypeChanges = ignore; }
00647 
00650     const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00651 
00654     void SetReportTimeInterval(
00655       const PTimeInterval & interval 
00656     )  { reportTimeInterval = interval; }
00657 
00660     PTimeInterval GetReportTimer()
00661     { return reportTimer; }
00662 
00665     unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00666 
00669     void SetTxStatisticsInterval(
00670       unsigned packets   
00671     );
00672 
00675     unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00676 
00679     void SetRxStatisticsInterval(
00680       unsigned packets   
00681     );
00682 
00685     DWORD GetPacketsSent() const { return packetsSent; }
00686 
00689     DWORD GetOctetsSent() const { return octetsSent; }
00690 
00693     DWORD GetPacketsReceived() const { return packetsReceived; }
00694 
00697     DWORD GetOctetsReceived() const { return octetsReceived; }
00698 
00701     DWORD GetPacketsLost() const { return packetsLost; }
00702 
00705     DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00706 
00709     DWORD GetPacketsTooLate() const;
00710 
00713     DWORD GetPacketOverruns() const;
00714 
00719     DWORD GetAverageSendTime() const { return averageSendTime; }
00720 
00725     DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00726 
00731     DWORD GetMarkerSendCount() const { return markerSendCount; }
00732 
00737     DWORD GetMaximumSendTime() const { return maximumSendTime; }
00738 
00743     DWORD GetMinimumSendTime() const { return minimumSendTime; }
00744 
00749     DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00750 
00755     DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00756 
00761     DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00762 
00767     DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00768 
00772     DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00774 
00777     virtual int GetDataSocketHandle() const
00778     { return -1; }
00779     virtual int GetControlSocketHandle() const
00780     { return -1; }
00782 
00783     virtual void SetCloseOnBYE(PBoolean v)  { closeOnBye = v; }
00784 
00789     virtual void SendIntraFrameRequest();
00790 
00791     void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00792 
00793     virtual PString GetEncoding() const { return m_encoding; }
00794     virtual void SetEncoding(const PString & newEncoding);
00795 
00796     DWORD GetSyncSourceIn() const { return syncSourceIn; }
00797 
00798     class EncodingLock
00799     {
00800       public:
00801         EncodingLock(RTP_Session & _session);
00802         ~EncodingLock();
00803 
00804         __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00805 
00806       protected:
00807         RTP_Session  & session;
00808         RTP_Encoding * m_encodingHandler;
00809     };
00810 
00811     friend class EncodingLock; 
00812 
00813   protected:
00814     virtual void SendBYE();
00815     void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00816     PBoolean InsertReportPacket(RTP_ControlFrame & report);
00817 
00818     PString             m_encoding;
00819     PMutex              m_encodingMutex;
00820     RTP_Encoding      * m_encodingHandler;
00821 
00822     unsigned           sessionID;
00823     bool               isAudio;
00824     PString            canonicalName;
00825     PString            toolName;
00826     RTP_UserData     * userData;
00827     PBoolean           autoDeleteUserData;
00828     RTP_JitterBuffer * jitter;
00829 
00830     PBoolean      ignoreOutOfOrderPackets;
00831     DWORD         syncSourceOut;
00832     DWORD         syncSourceIn;
00833     DWORD         lastSentTimestamp;
00834     bool          allowAnySyncSource;
00835     bool          allowOneSyncSourceChange;
00836     PBoolean      allowRemoteTransmitAddressChange;
00837     PBoolean      allowSequenceChange;
00838     PTimeInterval reportTimeInterval;
00839     unsigned      txStatisticsInterval;
00840     unsigned      rxStatisticsInterval;
00841     WORD          lastSentSequenceNumber;
00842     WORD          expectedSequenceNumber;
00843     PTimeInterval lastSentPacketTime;
00844     PTimeInterval lastReceivedPacketTime;
00845     WORD          lastRRSequenceNumber;
00846     PINDEX        consecutiveOutOfOrderPackets;
00847 
00848     PMutex        dataMutex;
00849     DWORD         timeStampOffs;               // offset between incoming media timestamp and timeStampOut
00850     PBoolean      oobTimeStampBaseEstablished; // PTrue if timeStampOffs has been established by media
00851     DWORD         oobTimeStampOutBase;         // base timestamp value for oob data
00852     PTimeInterval oobTimeStampBase;            // base time for oob timestamp
00853 
00854     // Statistics
00855     DWORD packetsSent;
00856     DWORD rtcpPacketsSent;
00857     DWORD octetsSent;
00858     DWORD packetsReceived;
00859     DWORD octetsReceived;
00860     DWORD packetsLost;
00861     DWORD packetsOutOfOrder;
00862     DWORD averageSendTime;
00863     DWORD maximumSendTime;
00864     DWORD minimumSendTime;
00865     DWORD averageReceiveTime;
00866     DWORD maximumReceiveTime;
00867     DWORD minimumReceiveTime;
00868     DWORD jitterLevel;
00869     DWORD maximumJitterLevel;
00870 
00871     DWORD markerSendCount;
00872     DWORD markerRecvCount;
00873 
00874     unsigned txStatisticsCount;
00875     unsigned rxStatisticsCount;
00876 
00877     DWORD    averageSendTimeAccum;
00878     DWORD    maximumSendTimeAccum;
00879     DWORD    minimumSendTimeAccum;
00880     DWORD    averageReceiveTimeAccum;
00881     DWORD    maximumReceiveTimeAccum;
00882     DWORD    minimumReceiveTimeAccum;
00883     DWORD    packetsLostSinceLastRR;
00884     DWORD    lastTransitTime;
00885     
00886     RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00887     PBoolean ignorePayloadTypeChanges;
00888 
00889     PMutex reportMutex;
00890     PTimer reportTimer;
00891 
00892 #if OPAL_RTP_AGGREGATE
00893     PHandleAggregator * aggregator;
00894 #endif
00895 
00896     PBoolean closeOnBye;
00897     PBoolean byeSent;
00898 };
00899 
00902 class RTP_UDP : public RTP_Session
00903 {
00904   PCLASSINFO(RTP_UDP, RTP_Session);
00905 
00906   public:
00911     RTP_UDP(
00912       const PString & _format,
00913 #if OPAL_RTP_AGGREGATE
00914       PHandleAggregator * aggregator, 
00915 #endif
00916       unsigned id,                    
00917       PBoolean remoteIsNAT                
00918     );
00919 
00921     ~RTP_UDP();
00923 
00931     virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
00932     virtual PBoolean Internal_ReadData(RTP_DataFrame & frame, PBoolean loop);
00933 
00936     virtual PBoolean WriteData(RTP_DataFrame & frame);
00937     virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
00938 
00942     virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
00943 
00946     virtual PBoolean WriteControl(RTP_ControlFrame & frame);
00947 
00950     virtual void Close(
00951       PBoolean reading    
00952     );
00953 
00956     virtual PString GetLocalHostName();
00958 
00961     virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
00962 
00967     virtual PBoolean Open(
00968       PIPSocket::Address localAddress,  
00969       WORD portBase,                    
00970       WORD portMax,                     
00971       BYTE ipTypeOfService,             
00972       PNatMethod * natMethod = NULL,    
00973       RTP_QOS * rtpqos = NULL           
00974     );
00976 
00979     virtual void Reopen(PBoolean isReading);
00981 
00986     virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
00987 
00990     virtual void SetLocalAddress(
00991       const PIPSocket::Address & addr
00992     ) { localAddress = addr; }
00993 
00996     PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
00997 
01000     virtual WORD GetLocalDataPort() const { return localDataPort; }
01001 
01004     virtual WORD GetLocalControlPort() const { return localControlPort; }
01005 
01008     virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01009 
01012     virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01013 
01016     virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01017 
01020     virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01021 
01024     virtual PBoolean SetRemoteSocketInfo(
01025       PIPSocket::Address address,   
01026       WORD port,                    
01027       PBoolean isDataPort               
01028     );
01029 
01032     virtual void ApplyQOS(
01033       const PIPSocket::Address & addr
01034     );
01036 
01037     virtual int GetDataSocketHandle() const
01038     { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01039 
01040     virtual int GetControlSocketHandle() const
01041     { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01042 
01043     friend class RTP_Encoding;
01044 
01045     virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01046     virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01047 
01048     virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01049     virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01050 
01051     virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01052     virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01053 
01054     virtual SendReceiveStatus ReadControlPDU();
01055     virtual SendReceiveStatus ReadDataOrControlPDU(
01056       BYTE * framePtr,
01057       PINDEX frameSize,
01058       PBoolean fromDataChannel
01059     );
01060     
01061     virtual bool WriteDataPDU(RTP_DataFrame & frame);
01062     virtual bool WriteDataOrControlPDU(
01063       const BYTE * framePtr,
01064       PINDEX frameSize,
01065       bool toDataChannel
01066     );
01067 
01068 
01069   protected:
01070     PIPSocket::Address localAddress;
01071     WORD               localDataPort;
01072     WORD               localControlPort;
01073 
01074     PIPSocket::Address remoteAddress;
01075     WORD               remoteDataPort;
01076     WORD               remoteControlPort;
01077 
01078     PIPSocket::Address remoteTransmitAddress;
01079 
01080     PUDPSocket * dataSocket;
01081     PUDPSocket * controlSocket;
01082 
01083     bool shutdownRead;
01084     bool shutdownWrite;
01085     bool appliedQOS;
01086     bool remoteIsNAT;
01087     bool localHasNAT;
01088     bool first;
01089     int  badTransmitCounter;
01090 };
01091 
01093 
01094 class RTP_UDP;
01095 
01096 class RTP_Encoding
01097 {
01098   public:
01099     RTP_Encoding();
01100     virtual ~RTP_Encoding();
01101     virtual void OnStart(RTP_Session & _rtpSession);
01102     virtual void OnFinish();
01103     virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01104     virtual PBoolean WriteData(RTP_DataFrame & frame);
01105     virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01106     virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01107     virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01108     virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01109     virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01110     virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
01111     virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01112 
01113     PMutex      mutex;
01114     unsigned    refCount;
01115 
01116   protected:
01117     RTP_UDP     * rtpUDP;
01118 };
01119 
01121 
01122 class SecureRTP_UDP : public RTP_UDP
01123 {
01124   PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01125 
01126   public:
01131     SecureRTP_UDP(
01132       const PString & encoding,       
01133 #if OPAL_RTP_AGGREGATE
01134       PHandleAggregator * aggregator, 
01135 #endif
01136       unsigned id,                    
01137       PBoolean remoteIsNAT                
01138     );
01139 
01141     ~SecureRTP_UDP();
01142 
01143     virtual void SetSecurityMode(OpalSecurityMode * srtpParms);  
01144     virtual OpalSecurityMode * GetSecurityParms() const;
01145 
01146   protected:
01147     OpalSecurityMode * securityParms;
01148 };
01149 
01150 #endif // __OPAL_RTP_H
01151 

Generated on Mon Sep 15 11:49:15 2008 for OPAL by  doxygen 1.5.1