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: 23097 $
00030  * $Author: rjongbloed $
00031  * $Date: 2009-07-12 16:57:28 +0000 (Sun, 12 Jul 2009) $
00032  */
00033 
00034 #ifndef OPAL_RTP_RTP_H
00035 #define OPAL_RTP_RTP_H
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 #include <opal/buildopts.h>
00042 
00043 #include <ptlib/sockets.h>
00044 #include <ptlib/safecoll.h>
00045 
00046 
00047 class RTP_JitterBuffer;
00048 class PNatMethod;
00049 class OpalSecurityMode;
00050 
00052 // 
00053 // class to hold the QoS definitions for an RTP channel
00054 
00055 class RTP_QOS : public PObject
00056 {
00057   PCLASSINFO(RTP_QOS,PObject);
00058   public:
00059     PQoS dataQoS;
00060     PQoS ctrlQoS;
00061 };
00062 
00064 // Real Time Protocol - IETF RFC1889 and RFC1890
00065 
00068 class RTP_DataFrame : public PBYTEArray
00069 {
00070   PCLASSINFO(RTP_DataFrame, PBYTEArray);
00071 
00072   public:
00073     RTP_DataFrame(PINDEX payloadSize = 0, PINDEX bufferSize = 0);
00074     RTP_DataFrame(const BYTE * data, PINDEX len, PBoolean dynamic = PTrue);
00075 
00076     enum {
00077       ProtocolVersion = 2,
00078       MinHeaderSize = 12,
00079       // Max safe MTU size (576 bytes as per RFC879) minus IP, UDP an RTP headers
00080       MaxMtuPayloadSize = (576-20-16-12)
00081     };
00082 
00083     enum PayloadTypes {
00084       PCMU,         // G.711 u-Law
00085       FS1016,       // Federal Standard 1016 CELP
00086       G721,         // ADPCM - Subsumed by G.726
00087       G726 = G721,
00088       GSM,          // GSM 06.10
00089       G7231,        // G.723.1 at 6.3kbps or 5.3 kbps
00090       DVI4_8k,      // DVI4 at 8kHz sample rate
00091       DVI4_16k,     // DVI4 at 16kHz sample rate
00092       LPC,          // LPC-10 Linear Predictive CELP
00093       PCMA,         // G.711 A-Law
00094       G722,         // G.722
00095       L16_Stereo,   // 16 bit linear PCM
00096       L16_Mono,     // 16 bit linear PCM
00097       G723,         // G.723
00098       CN,           // Confort Noise
00099       MPA,          // MPEG1 or MPEG2 audio
00100       G728,         // G.728 16kbps CELP
00101       DVI4_11k,     // DVI4 at 11kHz sample rate
00102       DVI4_22k,     // DVI4 at 22kHz sample rate
00103       G729,         // G.729 8kbps
00104       Cisco_CN,     // Cisco systems comfort noise (unofficial)
00105 
00106       CelB = 25,    // Sun Systems Cell-B video
00107       JPEG,         // Motion JPEG
00108       H261 = 31,    // H.261
00109       MPV,          // MPEG1 or MPEG2 video
00110       MP2T,         // MPEG2 transport system
00111       H263,         // H.263
00112 
00113       LastKnownPayloadType,
00114 
00115       DynamicBase = 96,
00116       MaxPayloadType = 127,
00117       IllegalPayloadType
00118     };
00119 
00120     unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00121 
00122     PBoolean GetExtension() const   { return (theArray[0]&0x10) != 0; }
00123     void SetExtension(PBoolean ext);
00124 
00125     PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00126     void SetMarker(PBoolean m);
00127 
00128     bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00129     void SetPadding(bool v)  { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00130 
00131     unsigned GetPaddingSize() const;
00132 
00133     PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00134     void         SetPayloadType(PayloadTypes t);
00135 
00136     WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00137     void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00138 
00139     DWORD GetTimestamp() const  { return *(PUInt32b *)&theArray[4]; }
00140     void  SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00141 
00142     DWORD GetSyncSource() const  { return *(PUInt32b *)&theArray[8]; }
00143     void  SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00144 
00145     PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00146     DWORD  GetContribSource(PINDEX idx) const;
00147     void   SetContribSource(PINDEX idx, DWORD src);
00148 
00149     PINDEX GetHeaderSize() const;
00150 
00151     int GetExtensionType() const; // -1 is no extension
00152     void   SetExtensionType(int type);
00153     PINDEX GetExtensionSize() const;
00154     PBoolean   SetExtensionSize(PINDEX sz);
00155     BYTE * GetExtensionPtr() const;
00156 
00157     PINDEX GetPayloadSize() const { return payloadSize - GetPaddingSize(); }
00158     PBoolean   SetPayloadSize(PINDEX sz);
00159     BYTE * GetPayloadPtr()     const { return (BYTE *)(theArray+GetHeaderSize()); }
00160 
00161     virtual void PrintOn(ostream & strm) const;
00162 
00163   protected:
00164     PINDEX payloadSize;
00165 
00166 #if PTRACING
00167     friend ostream & operator<<(ostream & o, PayloadTypes t);
00168 #endif
00169 };
00170 
00171 PLIST(RTP_DataFrameList, RTP_DataFrame);
00172 
00173 
00176 class RTP_ControlFrame : public PBYTEArray
00177 {
00178   PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00179 
00180   public:
00181     RTP_ControlFrame(PINDEX compoundSize = 2048);
00182 
00183     unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00184 
00185     unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00186     void     SetCount(unsigned count);
00187 
00188     enum PayloadTypes {
00189       e_IntraFrameRequest = 192,
00190       e_SenderReport = 200,
00191       e_ReceiverReport,
00192       e_SourceDescription,
00193       e_Goodbye,
00194       e_ApplDefined
00195     };
00196 
00197     unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00198     void     SetPayloadType(unsigned t);
00199 
00200     PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00201     void   SetPayloadSize(PINDEX sz);
00202 
00203     BYTE * GetPayloadPtr() const;
00204 
00205     PBoolean ReadNextPacket();
00206     PBoolean StartNewPacket();
00207     void EndPacket();
00208 
00209     PINDEX GetCompoundSize() const;
00210 
00211     void Reset(PINDEX size);
00212 
00213 #pragma pack(1)
00214     struct ReceiverReport {
00215       PUInt32b ssrc;      /* data source being reported */
00216       BYTE fraction;      /* fraction lost since last SR/RR */
00217       BYTE lost[3];       /* cumulative number of packets lost (signed!) */
00218       PUInt32b last_seq;  /* extended last sequence number received */
00219       PUInt32b jitter;    /* interarrival jitter */
00220       PUInt32b lsr;       /* last SR packet from this source */
00221       PUInt32b dlsr;      /* delay since last SR packet */
00222 
00223       unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00224       void SetLostPackets(unsigned lost);
00225     };
00226 
00227     struct SenderReport {
00228       PUInt32b ntp_sec;   /* NTP timestamp */
00229       PUInt32b ntp_frac;
00230       PUInt32b rtp_ts;    /* RTP timestamp */
00231       PUInt32b psent;     /* packets sent */
00232       PUInt32b osent;     /* octets sent */ 
00233     };
00234 
00235     enum DescriptionTypes {
00236       e_END,
00237       e_CNAME,
00238       e_NAME,
00239       e_EMAIL,
00240       e_PHONE,
00241       e_LOC,
00242       e_TOOL,
00243       e_NOTE,
00244       e_PRIV,
00245       NumDescriptionTypes
00246     };
00247 
00248     struct SourceDescription {
00249       PUInt32b src;       /* first SSRC/CSRC */
00250       struct Item {
00251         BYTE type;        /* type of SDES item (enum DescriptionTypes) */
00252         BYTE length;      /* length of SDES item (in octets) */
00253         char data[1];     /* text, not zero-terminated */
00254 
00255         /* WARNING, SourceDescription may not be big enough to contain length and data, for 
00256            instance, when type == RTP_ControlFrame::e_END.
00257            Be careful whan calling the following function of it may read to over to 
00258            memory allocated*/
00259         unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);} 
00260         const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00261         Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00262       } item[1];          /* list of SDES items */
00263     };
00264 
00265     void StartSourceDescription(
00266       DWORD src   
00267     );
00268 
00269     void AddSourceDescriptionItem(
00270       unsigned type,            
00271       const PString & data      
00272     );
00273 #pragma pack()
00274 
00275   protected:
00276     PINDEX compoundOffset;
00277     PINDEX payloadSize;
00278 };
00279 
00280 
00281 class RTP_Session;
00282 
00284 
00285 #if OPAL_STATISTICS
00286 
00289 class OpalMediaStatistics : public PObject
00290 {
00291     PCLASSINFO(OpalMediaStatistics, PObject);
00292   public:
00293     OpalMediaStatistics();
00294 
00295     // General info (typicallly from RTP)
00296     PUInt64  m_totalBytes;
00297     unsigned m_totalPackets;
00298     unsigned m_packetsLost;
00299     unsigned m_packetsOutOfOrder;
00300     unsigned m_packetsTooLate;
00301     unsigned m_packetOverruns;
00302     unsigned m_minimumPacketTime;
00303     unsigned m_averagePacketTime;
00304     unsigned m_maximumPacketTime;
00305 
00306     // Audio
00307     unsigned m_averageJitter;
00308     unsigned m_maximumJitter;
00309 
00310     // Video
00311     unsigned m_totalFrames;
00312     unsigned m_keyFrames;
00313 
00314     // Fax
00315 #if OPAL_FAX
00316     struct Fax {
00317       Fax();
00318 
00319       int  m_result;      // -2=not started, -1=progress, 0=success, >0=ended with error
00320       int  m_bitRate;     // e.g. 14400, 9600
00321       int  m_compression; // 0=N/A, 1=T.4 1d, 2=T.4 2d, 3=T.6
00322       bool m_errorCorrection;
00323       int  m_txPages;
00324       int  m_rxPages;
00325       int  m_totalPages;
00326       int  m_imageSize;   // In bytes
00327       int  m_resolutionX; // Pixels per inch
00328       int  m_resolutionY; // Pixels per inch
00329       int  m_pageWidth;
00330       int  m_pageHeight;
00331       int  m_badRows;     // Total number of bad rows
00332       int  m_mostBadRows; // Longest run of bad rows
00333       int  m_errorCorrectionRetries;
00334     } m_fax;
00335 #endif
00336 };
00337 
00338 #endif
00339 
00340 
00345 class RTP_UserData : public PObject
00346 {
00347   PCLASSINFO(RTP_UserData, PObject);
00348 
00349   public:
00356     virtual void OnTxStatistics(
00357       const RTP_Session & session   
00358     ) const;
00359 
00366     virtual void OnRxStatistics(
00367       const RTP_Session & session   
00368     ) const;
00369 
00370 #if OPAL_VIDEO
00371 
00376     virtual void OnTxIntraFrameRequest(
00377       const RTP_Session & session   
00378     ) const;
00379 
00385     virtual void OnRxIntraFrameRequest(
00386       const RTP_Session & session   
00387     ) const;
00388 #endif
00389 
00393     virtual void SessionFailing(
00394       RTP_Session & session   
00395     );
00396 };
00397 
00398 class RTP_Encoding;
00399 
00400 
00403 class RTP_Session : public PObject
00404 {
00405   PCLASSINFO(RTP_Session, PObject);
00406 
00407   public:
00410     struct Params {
00411       Params()
00412         : id(0)
00413         , userData(NULL)
00414         , autoDelete(true)
00415         , isAudio(false)
00416         , remoteIsNAT(false)
00417       { }
00418 
00419       PString             encoding;    
00420       unsigned            id;          
00421       RTP_UserData      * userData;    
00422       bool                autoDelete;  
00423       bool                isAudio;     
00424       bool                remoteIsNAT; 
00425     };
00426 
00429     RTP_Session(
00430       const Params & options 
00431     );
00432 
00436     ~RTP_Session();
00438 
00448     void SetJitterBufferSize(
00449       unsigned minJitterDelay, 
00450       unsigned maxJitterDelay, 
00451       unsigned timeUnits = 8,  
00452       PINDEX packetSize = 2048 
00453     );
00454 
00460     unsigned GetJitterBufferSize() const;
00461     
00464     unsigned GetJitterTimeUnits() const;
00465 
00467     virtual PBoolean ModifyQOS(RTP_QOS * )
00468     { return PFalse; }
00469 
00475     virtual PBoolean ReadBufferedData(
00476       RTP_DataFrame & frame   
00477     );
00478 
00484     virtual PBoolean ReadData(
00485       RTP_DataFrame & frame,  
00486       PBoolean loop               
00487     ) = 0;
00488 
00491     virtual PBoolean WriteData(
00492       RTP_DataFrame & frame   
00493     ) = 0;
00494 
00498     virtual PBoolean WriteOOBData(
00499       RTP_DataFrame & frame,
00500       bool rewriteTimeStamp = true
00501     );
00502 
00505     virtual PBoolean WriteControl(
00506       RTP_ControlFrame & frame    
00507     ) = 0;
00508 
00511     virtual PBoolean SendReport();
00512 
00515     virtual void Close(
00516       PBoolean reading    
00517     ) = 0;
00518 
00521     virtual void Reopen(
00522       PBoolean isReading
00523     ) = 0;
00524 
00527     virtual PString GetLocalHostName() = 0;
00528 
00529 #if OPAL_STATISTICS
00530     virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00531 #endif
00532 
00533 
00536     enum SendReceiveStatus {
00537       e_ProcessPacket,
00538       e_IgnorePacket,
00539       e_AbortTransport
00540     };
00541     virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00542     virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00543 
00544     virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00545     virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00546 
00547     virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00548     virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00549 
00550     virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00551 
00552     class ReceiverReport : public PObject  {
00553         PCLASSINFO(ReceiverReport, PObject);
00554       public:
00555         void PrintOn(ostream &) const;
00556 
00557         DWORD sourceIdentifier;
00558         DWORD fractionLost;         /* fraction lost since last SR/RR */
00559         DWORD totalLost;            /* cumulative number of packets lost (signed!) */
00560         DWORD lastSequenceNumber;   /* extended last sequence number received */
00561         DWORD jitter;               /* interarrival jitter */
00562         PTimeInterval lastTimestamp;/* last SR packet from this source */
00563         PTimeInterval delay;        /* delay since last SR packet */
00564     };
00565     PARRAY(ReceiverReportArray, ReceiverReport);
00566 
00567     class SenderReport : public PObject  {
00568         PCLASSINFO(SenderReport, PObject);
00569       public:
00570         void PrintOn(ostream &) const;
00571 
00572         DWORD sourceIdentifier;
00573         PTime realTimestamp;
00574         DWORD rtpTimestamp;
00575         DWORD packetsSent;
00576         DWORD octetsSent;
00577     };
00578     virtual void OnRxSenderReport(const SenderReport & sender,
00579                                   const ReceiverReportArray & reports);
00580     virtual void OnRxReceiverReport(DWORD src,
00581                                     const ReceiverReportArray & reports);
00582 
00583     class SourceDescription : public PObject  {
00584         PCLASSINFO(SourceDescription, PObject);
00585       public:
00586         SourceDescription(DWORD src) { sourceIdentifier = src; }
00587         void PrintOn(ostream &) const;
00588 
00589         DWORD            sourceIdentifier;
00590         POrdinalToString items;
00591     };
00592     PARRAY(SourceDescriptionArray, SourceDescription);
00593     virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00594 
00595     virtual void OnRxGoodbye(const PDWORDArray & sources,
00596                              const PString & reason);
00597 
00598     virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00599                                  const BYTE * data, PINDEX size);
00601 
00606     unsigned GetSessionID() const { return sessionID; }
00607 
00610     void SetSessionID(unsigned id) { sessionID = id; }
00611 
00614     bool IsAudio() const { return isAudio; }
00615 
00618     void SetAudio(
00619       bool aud    
00620     ) { isAudio = aud; }
00621 
00624     PString GetCanonicalName() const;
00625 
00628     void SetCanonicalName(const PString & name);
00629 
00632     PString GetToolName() const;
00633 
00636     void SetToolName(const PString & name);
00637 
00640     RTP_UserData * GetUserData() const { return userData; }
00641 
00644     void SetUserData(
00645       RTP_UserData * data,            
00646       PBoolean autoDeleteUserData = PTrue  
00647     );
00648 
00651     DWORD GetSyncSourceOut() const { return syncSourceOut; }
00652 
00655     bool AllowAnySyncSource() const { return allowAnySyncSource; }
00656 
00659     void SetAnySyncSource(
00660       bool allow    
00661     ) { allowAnySyncSource = allow; }
00662 
00665     PBoolean WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00666 
00669     void SetIgnoreOutOfOrderPackets(
00670       PBoolean ignore   
00671     ) { ignoreOutOfOrderPackets = ignore; }
00672 
00675     void SetIgnorePayloadTypeChanges(
00676       PBoolean ignore   
00677     ) { ignorePayloadTypeChanges = ignore; }
00678 
00681     const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00682 
00685     void SetReportTimeInterval(
00686       const PTimeInterval & interval 
00687     )  { reportTimeInterval = interval; }
00688 
00691     PTimeInterval GetReportTimer()
00692     { return reportTimer; }
00693 
00696     unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00697 
00700     void SetTxStatisticsInterval(
00701       unsigned packets   
00702     );
00703 
00706     unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00707 
00710     void SetRxStatisticsInterval(
00711       unsigned packets   
00712     );
00713 
00716     void ClearStatistics();
00717 
00720     DWORD GetPacketsSent() const { return packetsSent; }
00721 
00724     DWORD GetOctetsSent() const { return octetsSent; }
00725 
00728     DWORD GetPacketsReceived() const { return packetsReceived; }
00729 
00732     DWORD GetOctetsReceived() const { return octetsReceived; }
00733 
00736     DWORD GetPacketsLost() const { return packetsLost; }
00737 
00740     DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00741 
00744     DWORD GetPacketsTooLate() const;
00745 
00748     DWORD GetPacketOverruns() const;
00749 
00754     DWORD GetAverageSendTime() const { return averageSendTime; }
00755 
00760     DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00761 
00766     DWORD GetMarkerSendCount() const { return markerSendCount; }
00767 
00772     DWORD GetMaximumSendTime() const { return maximumSendTime; }
00773 
00778     DWORD GetMinimumSendTime() const { return minimumSendTime; }
00779 
00784     DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00785 
00790     DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00791 
00796     DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00797 
00802     DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00803 
00807     DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00809 
00810     virtual void SetCloseOnBYE(PBoolean v)  { closeOnBye = v; }
00811 
00816     virtual void SendIntraFrameRequest();
00817 
00818     void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00819 
00820     virtual PString GetEncoding() const { return m_encoding; }
00821     virtual void SetEncoding(const PString & newEncoding);
00822 
00823     DWORD GetSyncSourceIn() const { return syncSourceIn; }
00824 
00825     class EncodingLock
00826     {
00827       public:
00828         EncodingLock(RTP_Session & _session);
00829         ~EncodingLock();
00830 
00831         __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00832 
00833       protected:
00834         RTP_Session  & session;
00835         RTP_Encoding * m_encodingHandler;
00836     };
00837 
00838     friend class EncodingLock; 
00839 
00840     void SetFailed(bool v)
00841     { failed = v; }
00842 
00843     bool HasFailed() const
00844     { return failed; }
00845 
00846     void AddFilter(const PNotifier & filter);
00847 
00848   protected:
00849     virtual void SendBYE();
00850     void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00851     PBoolean InsertReportPacket(RTP_ControlFrame & report);
00852 
00853     PString             m_encoding;
00854     PMutex              m_encodingMutex;
00855     RTP_Encoding      * m_encodingHandler;
00856 
00857     unsigned           sessionID;
00858     bool               isAudio;
00859     PString            canonicalName;
00860     PString            toolName;
00861     RTP_UserData     * userData;
00862     PBoolean           autoDeleteUserData;
00863 
00864     typedef PSafePtr<RTP_JitterBuffer, PSafePtrMultiThreaded> JitterBufferPtr;
00865     JitterBufferPtr m_jitterBuffer;
00866 
00867     PBoolean      ignoreOutOfOrderPackets;
00868     DWORD         syncSourceOut;
00869     DWORD         syncSourceIn;
00870     DWORD         lastSentTimestamp;
00871     bool          allowAnySyncSource;
00872     bool          allowOneSyncSourceChange;
00873     PBoolean      allowRemoteTransmitAddressChange;
00874     PBoolean      allowSequenceChange;
00875     PTimeInterval reportTimeInterval;
00876     unsigned      txStatisticsInterval;
00877     unsigned      rxStatisticsInterval;
00878     WORD          lastSentSequenceNumber;
00879     WORD          expectedSequenceNumber;
00880     PTimeInterval lastSentPacketTime;
00881     PTimeInterval lastReceivedPacketTime;
00882     WORD          lastRRSequenceNumber;
00883     PINDEX        consecutiveOutOfOrderPackets;
00884 
00885     PMutex        dataMutex;
00886     DWORD         timeStampOffs;               // offset between incoming media timestamp and timeStampOut
00887     PBoolean      oobTimeStampBaseEstablished; // PTrue if timeStampOffs has been established by media
00888     DWORD         oobTimeStampOutBase;         // base timestamp value for oob data
00889     PTimeInterval oobTimeStampBase;            // base time for oob timestamp
00890 
00891     // Statistics
00892     DWORD packetsSent;
00893     DWORD rtcpPacketsSent;
00894     DWORD octetsSent;
00895     DWORD packetsReceived;
00896     DWORD octetsReceived;
00897     DWORD packetsLost;
00898     DWORD packetsOutOfOrder;
00899     DWORD averageSendTime;
00900     DWORD maximumSendTime;
00901     DWORD minimumSendTime;
00902     DWORD averageReceiveTime;
00903     DWORD maximumReceiveTime;
00904     DWORD minimumReceiveTime;
00905     DWORD jitterLevel;
00906     DWORD maximumJitterLevel;
00907 
00908     DWORD markerSendCount;
00909     DWORD markerRecvCount;
00910 
00911     unsigned txStatisticsCount;
00912     unsigned rxStatisticsCount;
00913 
00914     DWORD    averageSendTimeAccum;
00915     DWORD    maximumSendTimeAccum;
00916     DWORD    minimumSendTimeAccum;
00917     DWORD    averageReceiveTimeAccum;
00918     DWORD    maximumReceiveTimeAccum;
00919     DWORD    minimumReceiveTimeAccum;
00920     DWORD    packetsLostSinceLastRR;
00921     DWORD    lastTransitTime;
00922     
00923     RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00924     PBoolean ignorePayloadTypeChanges;
00925 
00926     PMutex reportMutex;
00927     PTimer reportTimer;
00928 
00929     PBoolean closeOnBye;
00930     PBoolean byeSent;
00931     bool                failed;      
00932 
00933     class Filter : public PObject {
00934         PCLASSINFO(Filter, PObject);
00935       public:
00936         Filter(const PNotifier & n) : notifier(n) { }
00937         PNotifier notifier;
00938     };
00939     PList<Filter> filters;
00940 };
00941 
00944 class RTP_UDP : public RTP_Session
00945 {
00946   PCLASSINFO(RTP_UDP, RTP_Session);
00947 
00948   public:
00953     RTP_UDP(
00954       const Params & options 
00955     );
00956 
00958     ~RTP_UDP();
00960 
00968     virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
00969     virtual PBoolean Internal_ReadData(RTP_DataFrame & frame, PBoolean loop);
00970 
00973     virtual PBoolean WriteData(RTP_DataFrame & frame);
00974     virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
00975 
00979     virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
00980 
00983     virtual PBoolean WriteControl(RTP_ControlFrame & frame);
00984 
00987     virtual void Close(
00988       PBoolean reading    
00989     );
00990 
00993     virtual PString GetLocalHostName();
00995 
00998     virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
00999 
01004     virtual PBoolean Open(
01005       PIPSocket::Address localAddress,  
01006       WORD portBase,                    
01007       WORD portMax,                     
01008       BYTE ipTypeOfService,             
01009       PNatMethod * natMethod = NULL,    
01010       RTP_QOS * rtpqos = NULL           
01011     );
01013 
01016     virtual void Reopen(PBoolean isReading);
01018 
01023     virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
01024 
01027     virtual void SetLocalAddress(
01028       const PIPSocket::Address & addr
01029     ) { localAddress = addr; }
01030 
01033     PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01034 
01037     virtual WORD GetLocalDataPort() const { return localDataPort; }
01038 
01041     virtual WORD GetLocalControlPort() const { return localControlPort; }
01042 
01045     virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01046 
01049     virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01050 
01053     virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01054 
01057     virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01058 
01061     virtual PBoolean SetRemoteSocketInfo(
01062       PIPSocket::Address address,   
01063       WORD port,                    
01064       PBoolean isDataPort               
01065     );
01066 
01069     virtual void ApplyQOS(
01070       const PIPSocket::Address & addr
01071     );
01073 
01074     virtual int GetDataSocketHandle() const
01075     { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01076 
01077     virtual int GetControlSocketHandle() const
01078     { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01079 
01080     friend class RTP_Encoding;
01081 
01082     virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01083     virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01084 
01085     virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01086     virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01087 
01088     virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01089     virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01090 
01091     virtual SendReceiveStatus ReadControlPDU();
01092     virtual SendReceiveStatus ReadDataOrControlPDU(
01093       BYTE * framePtr,
01094       PINDEX frameSize,
01095       PBoolean fromDataChannel
01096     );
01097     
01098     virtual bool WriteDataPDU(RTP_DataFrame & frame);
01099     virtual bool WriteDataOrControlPDU(
01100       const BYTE * framePtr,
01101       PINDEX frameSize,
01102       bool toDataChannel
01103     );
01104 
01105 
01106   protected:
01107     PIPSocket::Address localAddress;
01108     WORD               localDataPort;
01109     WORD               localControlPort;
01110 
01111     PIPSocket::Address remoteAddress;
01112     WORD               remoteDataPort;
01113     WORD               remoteControlPort;
01114 
01115     PIPSocket::Address remoteTransmitAddress;
01116 
01117     PUDPSocket * dataSocket;
01118     PUDPSocket * controlSocket;
01119 
01120     bool shutdownRead;
01121     bool shutdownWrite;
01122     bool appliedQOS;
01123     bool remoteIsNAT;
01124     bool localHasNAT;
01125     bool first;
01126     int  badTransmitCounter;
01127     PTime badTransmitStart;
01128 };
01129 
01131 
01132 class RTP_UDP;
01133 
01134 class RTP_Encoding
01135 {
01136   public:
01137     RTP_Encoding();
01138     virtual ~RTP_Encoding();
01139     virtual void OnStart(RTP_Session & _rtpSession);
01140     virtual void OnFinish();
01141     virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01142     virtual PBoolean WriteData(RTP_DataFrame & frame, bool oob);
01143     virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01144     virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01145     virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01146     virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01147     virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01148     virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
01149     virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01150 
01151     PMutex      mutex;
01152     unsigned    refCount;
01153 
01154   protected:
01155     RTP_UDP     * rtpUDP;
01156 };
01157 
01158 PFACTORY_LOAD(RTP_Encoding);
01159 
01160 
01162 
01163 class SecureRTP_UDP : public RTP_UDP
01164 {
01165   PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01166 
01167   public:
01172     SecureRTP_UDP(
01173       const Params & options 
01174     );
01175 
01177     ~SecureRTP_UDP();
01178 
01179     virtual void SetSecurityMode(OpalSecurityMode * srtpParms);  
01180     virtual OpalSecurityMode * GetSecurityParms() const;
01181 
01182   protected:
01183     OpalSecurityMode * securityParms;
01184 };
01185 
01186 #endif // OPAL_RTP_RTP_H
01187 

Generated on Mon Aug 3 20:50:25 2009 for OPAL by  doxygen 1.5.1